Slack Setup
Enable Slack Channel
Create a New Slack Bottender App
Create Bottender App
is the best way to start building a new application in Bottender.
To create a project, run:
npx create-bottender-app my-app
Make sure that you checked the slack
option:
After finishing the Create Bottender App
process, bottender.config.js
, a config file, will be generated automatically for further channel settings.
Enable Slack Channel for Existing Apps
First, you need to have a bottender.config.js
file that sets channels.slack.enabled
as true
:
module.exports = {
channels: {
slack: {
enabled: true,
path: '/webhooks/slack',
accessToken: process.env.SLACK_ACCESS_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
// verificationToken: process.env.SLACK_VERIFICATION_TOKEN, // deprecated, use signingSecret
},
},
};
The default webhook path is /webhooks/slack
, but you can set your webhook path by path
field.
Complete Slack Channel Settings
To make a Slack bot work, you have to set up the following values:
- Slack Access Token
- Slack Signing Secret (or Verification Token)
- Webhook
Requirements
Before going further, we assumed that you already have:
- a Slack Account
- a Slack Workspace
Slack App & Bot User
Create a Slack App if you haven't.
Create a bot user within your Slack App.
Remember to install the Slack App in your workspace.
Note:
- If you are not familiar with how Slack bots work, you can find detailed instructions from Dialogflow's Slack Integration Document
Access Token & Signing Secret (or Verification Token)
bottender.config.js
looks up .env
for Slack access token and Slack verification token.
# .env
SLACK_ACCESS_TOKEN=
SLACK_SIGNING_SECRET=
# SLACK_VERIFICATION_TOKEN= # deprecated, use SLACK_SIGNING_SECRET
Follow the below steps to find your access token and signing secret (or verification token).
- Slack access token could is in Slack Developer Console → \${YourApp} → Install App → Bot User OAuth Access Token
- Slack signing secret could be found in Slack Developer Console → \${YourApp} → Basic Information → Signing Secret.
We recommend use signing secret instead of verification token, but we also support verification token:
- Slack verification token could be find in Slack Developer Console → \${YourApp} → Basic Information → Verification Token.
Webhook
After finishing the above settings, you can start your server with Slack webhook event listening using the following commands:
# in production mode
npm start
# or in development mode
npm run dev
When you run bottender in development mode, Bottender automatically run up a Ngrok client, and then you can get the information of webhook URL from the console like this:
App has started
slack webhook url: https://42bbf602.ngrok.io/webhooks/slack
server is running on 5000 port...
Then, you have to copy your Slack webhook URL to Slack Developer Console → \${YourApp} → Event Subscriptions, where you can pick which bot events to subscribe.
Note:
- If your bot doesn't respond after webhook settings, please take a closer look at bot events you subscribed to. Slack doesn't pick any bot events subscription by default. The first bot event you may subscribe to is
message.im
, which is the event whenever a user posts a direct message to your bot.- For more info about Slack Events, please refer to Slack's official doc, API Event Types