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,
verificationToken: process.env.SLACK_VERIFICATION_TOKEN,
},
},
};
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 Verification Token
- Webhook
Prequirements
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 & Verification Token
bottender.config.js
looks up .env
for Slack access token and Slack verification token.
# .env
SLACK_ACCESS_TOKEN=
SLACK_VERIFICATION_TOKEN=
Follow the below steps to find your access token and verification token.
- Slack access token could is in Slack Developer Console → \${YourApp} → Install App → Bot User OAuth Access Token
- Slack verification token could is 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