In my last post, I walked through the design of the Slack Translate Bot. Let’s get it up and running for you. And if you’re on the fence about whether the effort is worthwhile, I’m happy to shoot you an invite to my development Slack org so you can try it out and decide; just reply to this post and I’ll hook you up.
Getting this running is a bit of a chicken-and-egg problem, in that we have to deploy the app in two phases, the first so that Slack will agree that it exists and the second where we configure the app with the Slack permissions we need1.
This process can be a bit complicated. If you get stuck, reply to me or post a comment and I’ll try to be helpful. If you’d like a higher level of help, the folks at Owls Head are happy to engage in quick-win services project for you, including adding in more sophisticated features into the POC if you like.
The Process
1. Gettingan OpenAI API Key
If you have an OpenAI API Key (the kind that starts with sk-), then you’re all set. If not, then you need to create a new account with OpenAI. It’s a very simple process:
Copy and save your sk-… API key (as you get to see it just once)
Set a low (e.g., $15) limit on your monthly usage here: https://platform.openai.com/account/billing/limits It’s very good to set a low limit on your account; this will protect you in case of either a runaway process or a leak of your key.
2. Clone the App’s Repository
If you’re not a GitHub user, you’re going to need to sign up for an account — it’s free. Navigate to the repository here:
https://github.com/owlshead/slacktranslate
Once there, you’ll want to fork the repository. Off of the Fork box, pick “Create a new fork”:
Then, fill in the details
Enter a name, whatever you want …
Press Create fork.
Congratulations, you have a repository! You’ll need the URL from your repository for Heroku.
3. Setup Heroku, Part 1
I’m using Heroku because I think it’s probably familiar to folks in the Salesforce community, but you can host the code elsewhere. If Heroku is problematic for some reason, I can recommend https://railway.app as an alternative.
Start by creating a new app in Heroku:
The name is mostly irrelevant.
Select GitHub as the deployment method: anytime you update your repository, Heroku will deploy it to the server.2
There’s probably some steps involved in granting Heroku access to your GitHub account that I’m not seeing because it’s already set up.
Next, find the newly forked repository:
And press Connect!
Finally, enable automatic deploys:
This should build and start the application.
With it up and running, you need to grab the URL for it and we’ll go configure Slack! On the settings page, scroll down to find the URL:
Save that someplace safe for our next step.
4. Configure Slack
Configuring Slack takes a few steps, because we’re introducing a new application to it and configuring all the permissions and security around it. Which means you’ll need to have some amount of admin powers for your Slack organization. If you don’t, you won’t be able to complete the process. You may find it easier if you create a new Slack organization; this works just fine with a free Slack workspace.
Before we begin, create your two channels for the for the app. It doesn’t matter what you call them, I picked #english and #español, but it’s up to you.
Once you’re ready to start, navigate to https://api.slack.com/apps. Press the green button that says “Create New App”. Then, pick “From an app manifest” from the pop-up window. Next, choose the workspace you want to install the app into and press Next:
Next, we enter the manifest for the app. It’s short:
Remember I said to save the URL from Heroku? You’ll need to update your manifest with your URL (with /events added at the end). When that’s done, paste it into Slack:
Press Next, and then Create on the next step.
Now, go ahead and click “Install into workspace”:
You’ll have to pick a channel where it can post to; it’s kind of irrelevant, so I just use #general:
When this is done, you’re back at your main screen. At this point, Slack will call the “events” URLto see if your app is alive and responsive. With Heroku, unfortunately, there’s every chance the app is asleep and it takes too long to wake up to respond. So you may get a verification error. To fix that, on the left hand navigation for your app (in Slack api), find “Event Subscriptions” and click it. Now look to see if your URL is verified:
If it is, all is well. If not, there’s a “Verify” button you can press. You may have to do it a couple of times3, but eventually it should be Verified.
Now, from the left hand menu, click on “Incoming Webhooks”. Scroll to the bottom until you find4:
We’re going to add two new webhooks, one for our English channel, and one for our Spanish channel. For each one, press “Add New…”, select the channel from the dropdown, and click “allow”. When you’re done it should look like:
And you’re done with the configuration. Keep this tab open for our next step, however, as we’re going to fish a bunch of information out of Slack.
5. Setup Heroku, Part 2
Now that we’ve configured Slack for our app, we have a bunch of information we need to pass into our app to allow it to communicate. To do that, we navigate in Heroku to our App’s settings and scroll down to the config vars (you might have to click Reveal Config Vars). Here’s what it will look like when we’re finished adding in our variables:
These variables are passed into our application as environment variables (you can see the code pick it up via os.getenv()). The variables are:
OPENAI_API_KEY: this is the API key you were issued from OpenAI when you signed up with them.
SLACK_ENG_CHAN_ID and SLACK_ESP_CHAN_ID: these are the channel ids for the two Slack channels you’re using. Go into the Slack client, right click on a channel, pick View channel details, and from the bottom, copy the channel id: Store it in the correct environment variable and repeat for the other channel.
SLACK_ENG_URL and SLACK_ESP_URL are the Webhook URLs we created to post into those two channels.
SLACK_TOKEN is found on the OAuth & Permissions page:
SLACK_VERIFY is the verification token on the Basic Information page:
When you’ve set all those, you’ll want to restart your Heroku app: under the More button, pick Restart All Dynos. Now we’re firing on all … dynos.
6. Finishing up in Slack
One last step, go into the Slack client, and for each of the channels, do the following:
Right click on the channel, and View channel details.
Click on Integrations at the top.
Click on “Add an App”:
Click on “Add” for our translator app:
Et voilà! Slack is now a polyglot! Type something into one, and watch it pop out translated in the other.
Just a note, there can be some glitches if Heroku has put your app back to sleep again. You can “warm” your app by going to your URL without the /events; it will print a short Star Wars quote when it’s revived. At that point, things should run smoothly in Slack. (In production, we would not let our app sleep, but that would cost a bit more).
Final Thoughts
Phew.
There was a lot more to that than I remembered from when I first did it. Isn’t that always the way when you document things?
Oh, and you should go out to an AI image generator and get a better icon for your app, or you can use the one in the repository.
Next week I’ll run through the code itself to discuss how it works.
_____________________________________
In hindsight, I probably could have streamlined this a bit more, but these steps work… ↩︎
Personally, I find this more convenient that the Heroku CLI approach, as I’m already pushing my code out to GitHub and appreciate the automation. Additionally, if you do decide to use an alternative hosting server (e.g., railway.app), the process isn’t any different: push to GitHub == deploy new app. ↩︎
When you were first setting up the app, you could have picked one of your two channels to post to and only had to set up the other here. That would have been more efficient, but harder to explain. ↩︎
Telecommunications providers excel at network innovation but face a critical choice: divert resources to develop and maintain custom software or leverage specialized partners. While in-house development promises control and customization, it often leads to unforeseen...
Tuesday, October 14th, 4:30 – 7:30Visit Register for event venue. An Exclusive Panel Discussion During Dreamforce 2025 While Dreamforce showcases the future of enterprise technology, Owls Head is bringing together the women who are actively...
in AI on October 26, 2023 By Charles McGuinness See how chats can be a lot more interesting! To avoid burying the lede, let me start with a chat session showing the app we’ll discuss in this post....