Slack
- Local deployment
- Botpress Cloud (beta)
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
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 Create new app, select From scratch then give it a name. Remember your App's name, you'll need it in a few minutes.
Open the page Features, then select Interactivity & Shortcuts and turn the Interactivity switch to On.
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. Then, click OAuth & Permissions and add
chat:write
under the Scope > Bot Token Scopes section.
Open the page Features, then click App Home and under the Show Tabs section, check Allow users to send Slash commands and messages from the messages tab.
From the Settings, go to the Basic Information. Then, go to the Install app section, install the app by clicking the Install to Workspace button. On the next screen, click the Allow button.
In Botpress, edit
data/bots/<YOUR_BOT_ID>/bot.config.json
. In themessaging.channels.slack
section write this configuration:
enabled
: set totrue
;signingSecret
: take the valueSigning Secret
on the sectionBasic Information
>App Credentials
;useRTM
:false
(true
if you have a legacy app);botToken
: take the valueBot User OAuth Token
on the section OAuth & 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. Then, click Event Subscriptions and turn the Enable Events switch to On.
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.
caution
If the slack endpoint is responding with Cannot resolve challenge
. The configuration at step 9 is not set in the right place. The configuration need to be inside the chatbot configuration.
Under Subscribe to bot event, add
message.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 changes.A yellow banner will be displayed at the top of the screen. Click the reinstall your app link. On the next screen, click the Allow button.
Quit 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.
Requirements​
Create a Slack App​
You will need a Slack App to connect your bot to Slack
- Go to your apps page
- Click Create new app, select From scratch then give it a name. Remember your App's name, you'll need it in a few minutes
Channel Configuration​
Signing Secret​
The signing secret is used to verify webhook requests
- In the left sidebar, click on Settings > Basic Information
- Scroll down to App Credentials section. Copy paste the value of the signing secret to the Signing Secret channel configuration
Bot Token​
The bot token is used to authenticate requests made to the Slack API
- In the left sidebar, click on Features > OAuth & Permissions
- Add
chat:write
under the Scope > Bot Token Scopes section - Click on Install to Workspace in the OAuth Tokens for Your Workspace section
- Copy paste the value in Bot User OAuth Token to the Bot Token channel configuration
Save Configuration​
Channel configuration is complete, you can now click Save. It is important you save your configuration before configuring the webhooks, otherwise Slack will be unable to validate the webhook url
Webhook Configuration​
Events Webhook​
Slack sends regular events such as messages to the event webhook
- In the left sidebar, click on Features > Event Subscriptions
- Turn on events by click the On/Off button
- Under Subscribe to bot event, add
message.im
andmessage.channels
- Copy paste the webhook url provided in the channel configuration UI to the Request URL field
- Click the Save Changes button. Make sure your slack channel configuration is saved before doing this step, otherwise webhook validation will fail
- A yellow banner will be displayed at the top of the screen. Click the reinstall your App link
Interactivity Webhook​
Slack sends "interactive" events such as reactions to message to the interactivity webhook
- In the left sidebar, click on Features > Interactivity & Shortcuts
- Turn on interactivity by click the On/Off button
- Copy paste the webhook url provided in the channel configuration UI to the Request URL field
- Click the Save Changes button
Install App​
Add App to Workspace​
Your slack app needs to be added to your workspace to allow Slack users to communicate with it
- In the left sidebar, click on Features > App Home
- Scroll down and tick Allow users to send Slash commands and messages from the messages tab
- 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 Slack App