Slack Setup
Requirements
Before going further, we assume that you already have:
- a Slack Account
- a Slack Workspace
Slack App and 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
Enabling Slack Channels
To enable Slack channels, you can start either from new or existing Bottender apps.
New Bottender Apps
Create Bottender App is the best way to start building a new app in Bottender.
To create a project, run:
npx create-bottender-app my-app
Make sure to select the slack
option:
After you go through the steps, bottender.config.js
and .env
are generated automatically for further channel settings.
Existing Bottender Apps
First, you must have a bottender.config.js
file includes the following settings:
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
},
},
};
Make sure to set the channels.slack.enabled
field to true
.
By default, the Bottender server listens to the Slack requests on the /webhooks/slack
path. However, you can overwrite the path by assigning the preferred webhook path in the channels.slack.path
field.
We highly recommend setting your sensitive config using process.env
, so you could avoid any credentials get exposed.
Environment Configuration
Bottender utilizes the dotenv package to load your environment variables when developing your app.
To make a Slack bot work, you must prepare the following environment variables, which you may put into your .env
file later:
- Slack Access Token
- Slack Signing Secret (or Slack Verification Token)
Slack Access Token
You can find Slack access token in Slack Developer Console → \${YourApp} → Install App → Bot User OAuth Access Token
After you get your Slack Access Token, paste the value into the SLACK_ACCESS_TOKEN
field in your .env
file:
# .env
SLACK_ACCESS_TOKEN=<YOUR SLACK ACCESS TOKEN>
Slack Signing Secret
You can find Slack signing secret in Slack Developer Console → \${YourApp} → Basic Information → Signing Secret.
After you get your Slack Signing Secret, paste the value into the SLACK_SIGNING_SECRET
field in your .env
file:
# .env
SLACK_SIGNING_SECRET=<YOUR SLACK SIGNING SECRET>
Slack Verification Token (Deprecated)
We recommend using signing secret instead of verification token, but we also support verification token.
You can find Slack verification token in Slack Developer Console → \${YourApp} → Basic Information → Verification Token.
After you get your Slack Verification Token, paste the value into the SLACK_VERIFICATION_TOKEN
field in your .env
file:
# .env
# SLACK_VERIFICATION_TOKEN=<YOUR SLACK VERIFICATION TOKEN> # deprecated, use `SLACK_SIGNING_SECRET` instead
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.
For more information about Slack Events, please refer to Slack's official doc, API Event Types
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.