Slack
Requirements
HTTPS Endpoint
To connect to Slack, an HTTPS endpoint is required. Set the externalUrl
field in botpress.config.json. You can use the following methods to create this endpoint:
- Create an HTTPS tunnel to your machine using Ngrok. This tutorial works on pretty much any Operating System. Tutorial
- Using Nginx and Let's Encrypt. This tutorial is based on the Linux Ubuntu 16.04 Operating System. Tutorial
- Use Serveo to create an HTTPS tunnel to your machine. Tutorial
⭐ Note: To test on localhost, you can also use services like pagekite or tunnelme to expose your server.
Setup
Create your bot
First, you need a bot in Botpress. Take note of your bot's ID
Connecting your bot to Slack
Go to your apps page
Click on
Create new app
, selectFrom scratch
then give it a name. Remember your App's name, you'll need it in a few minutesOpen the page
Features
>Interactivity & Shortcuts
, then turn theInteractivity
switch toOn
Set the request URL to:
<EXTERNAL_URL>/api/v1/messaging/webhooks/<YOUR_BOT_ID>/slack/interactive
- Replace
EXTERNAL_URL
by the value ofexternalUrl
in yourbotpress.config.json
- Replace
YOUR_BOT_ID
with your bot ID
Save your changes
Open the page
Features
>OAuth & Permissions
and addchat:write
under theScopes
>Bot Token Scopes
sectionOpen the page
Features
>App Home
and under theShow Tabs
section, checkAllow users to send Slash commands and messages from the messages tab
From the
Settings
>Basic Information
>Install app
section, install the app by clicking theInstall to Workspace
button. On the next screen, click theAllow
buttonIn Botpress, edit
data/bots/<YOUR_BOT_ID>/bot.config.json
. In themessaging.channels.slack
section write this configuration :
enabled: Set to
true
signingSecret: Take the value
Signing Secret
on the sectionBasic Information
>App Credentials
useRTM:
false
(true
if you have a legacy app)botToken: Take the value
Bot User OAuth Token
on the sectionOAuth & Permissions
>OAuth Tokens for Your Workspace
Your
bot.config.json
should look like this :
{
// ... other data
"messaging": {
"channels": {
"slack": {
"enabled": true,
"signingSecret": "your_signing_secret",
"useRTM": false,
"botToken": "your_bot_token"
}
// ... other channels can also be configured here
}
}
}
Restart Botpress
Back on the your Slack app's page, open the page
Features
>Event Subscriptions
, then turn theEnable Events
switch toOn
Set the
Request URL
to:<EXTERNAL_URL>/api/v1/messaging/webhooks/<YOUR_BOT_ID>/slack/events
- Replace
EXTERNAL_URL
by the value ofexternalUrl
in yourbotpress.config.json
- Replace
YOUR_BOT_ID
with your bot ID
Under
Subscribe to bot events
, addmessage.im
andmessage.channels
(you can also add other types of messages if you want)Wait for the green
Verified
message to appear next toRequest URL
. Save your changesA yellow banner will be displayed at the top of the screen. Click the
reinstall your app
link. On the next screen, click theAllow
buttonQuit the Slack app and re-open it
In Slack, under the
Apps
section of the sidebar, click the+ Add apps
button. In the search bar, type the name of your Slack App. Click on your Slack app in the search results. You can now chat with your Botpress bot in Slack 🥳