owls head logo inline white
Get in touch

Chatting in the Global Village: A Simple Slack Translation Bot

in AI on October 11, 2023

By Charles McGuinness

Usually, when I embark on a project for this newsletter, it’s because I think it illustrates an important concept. And, yes, this one does. But this project is simple, effective, and has already proven itself quite valuable to me. I hope it will for you, too!

First, a story …

Last week, on a Slack group I’m in, folks were discussing a presentation I gave to a customer. But the conversation on that channel is in Portuguese, not English1. And my Portuguese is nonexistent. I could have wondered what they were saying about me. I could have painfully copy and pasted the text into Google Translate. But I did not need to do a thing.

I did not need to do a thing because, earlier last week, I wrote and deployed a Slack bot that automatically translated non-English messages into English. So I was able to follow along the conversation effortlessly. It was really cool; it felt a bit like spying!2 Still, it was valuable to know what was being said.

I admit I’m not the first person to think of a translation app. There’s about a half dozen of them in the Slack app directory. But building it turned out to be reasonably easy and is instructive for other ways that we can incorporate AI into Slack for just about any purpose. So let’s have a look at what is, how it works, and how it’s written?

The version I deployed has a bunch of idiosyncrasies that aren’t broadly relevant, so for this newsletter I created a simpler version of the bot that’s still very useful:

A simplified, yet very functional, version of the Bot

This version just does one thing: it supports two channels, one in English, one in Español, and translates and repost messages between the two of them. You can see a quick demo of it above.3

This version of the bot weighs in at just over 200 lines of code, which is very compact. But in that 200 lines of code it illustrates some of the interesting ways AI can be introduced into a Slack organization.4 I’ll walk through how it works and all of the steps it takes to stand it up. You never know, it might be just good enough for you to deploy as is as a POC to help generate interest in something more ambitious!

While simple, building even this scaled-down bot is a bit more complicated than building things on Salesforce5, as you have to host your application yourself (on Heroku or elsewhere) and set it up to communicate with Slack.

If you’re interested in a more powerful/customized version, or just want someone else to help set this up, Owls Head consulting can help you out! It can take as little as an hour to get things working for you!

It’s going to take a few posts to work through all the content. In this post, I’ll start with the overall design. If you read just this post, you’ll have a good understanding of how this works at a high level. In subsequent posts I’ll talk about how to configure Slack, the stand-alone application server, and how to build the application that ties everything together.

The Architecture

Here’s a high level overview of the architecture:

The four main components to this application are:

  1. Slack, which we will configure to interact with our application
  2. Our custom application, which creates an API that can be called from Slack and can call back into Slack as well.
  3. Heroku, which hosts our application.
  4. OpenAI, which is doing the translations.

How it Works

Slack

The process starts in Slack, where a user enters a message in one of the two language specific channels. Let’s say into #español. Because my app is installed into that channel and the app is registered to receive message events, Slack will call the app’s URL with the newly posted message (and metadata). That kicks off the processing in the app.

Our Application + Heroku

On the other side of that call from Slack is my application. When it receives the message event, it has to decide what to do with it: translate it or ignore it. Some messages you definitely want to ignore: after the app posts a translation, Slack turns around and calls the app back with the translated message it posted! Talk about a race condition if you’re not careful. There are other notifications we don’t care about too. So the app filters out everything but the newly-posted-by-a-human messages.

Typically in a REST call you return some sort of results when you’re done. But that’s not how it works here: Slack doesn’t want anything back beyond a 200 success code saying the app got the event. And it wants it kind of quickly, too, so there’s not enough time to always get a translation performed and post the results.

That means the code spins up a separate thread to translate the Spanish message into English. When that finishes, it posts the translation in Slack. It’s a few extra lines of code, but works perfectly for this scenario.

Speaking of our code, it has to run somewhere (and, importantly, have a https:// URL that Slack can call). Heroku hosts our code nicely on a $5/month plan making the cost trivial for a pilot.

OpenAI

We’re using gpt-3.5-turbo6 to do our translation. You can use any tool you like, but gpt is good at it and not very expensive to use for this kind of purpose. Using gpt opens the possibility of having business-specific instructions and fine-tuning and also demonstrates how you might use OpenAI for other Slack bot purposes. And as you might have guessed from yesterday’s post, another use is to have OpenAI do a toxicity score on the messages to make sure we stay out of trouble7.

How to get this Running (at a High Level)

You’re going to need to do the following:

  1. Find (or create) a Slack org to test on. You might need to bring cookies to bribe your Slack admin to get the right permissions. Or create a new one of your own.
  2. Create an OpenAI API account if you don’t have one already.
  3. Clone the app’s repository in GitHub
  4. Create an app in Heroku that imports the repository
  5. Configure the App
  6. Configure Slack

It’s a lot of steps just because we bounce back and forth between things a bit, but there’s nothing terribly challenging.

We’ll get started in the next post. Once you get it up and running, you’ll see it’s pretty straightforward to adapt and expand its capabilities to your unique need.

Final Thoughts

I built this for Owls Head’s company Slack, and they graciously put up with my debugging for a few days. After it was working, I noticed the COO was using it … and then others … and that’s when I knew it was a pretty darn useful tool.

PS: Seems appropriate for the topic:

  1. To be clear, the customer spoke English, the presentation was in English, so this was a bit of an unusual situation. ↩︎
  2. It might have felt like spying, but it was not. I was a member of the channel and could see, just not easily read, the messages. ↩︎
  3. I should have adopted a nom-de-Slack of Carlos in the Español channel! ↩︎
  4. And have no doubt, machine translation is very much AI. ↩︎
  5. Although by the time you work through Named Credentials → External Credentials → Principals → Permissions → Users, Salesforce can be very not easy. ↩︎
  6. GPT-4 is no doubt better, but more expensive. ↩︎
  7. It’s always those pinche gabachos, I tell you. ↩︎
Let's talk.

Read more articles

Redefining Telecom

Renato Reis

Embracing Innovation, Overcoming Barriers, and Shaping the Future The telecommunications industry is undergoing an unprecedented digital revolution driven by innovation, disruption, and an unrelenting demand for seamless connectivity in an ultra-competitive market.  To make our...

owls head logo inline whitegroup 51
© Copyright 2025 Owls Head Digitial, Inc.
crossmenu