Slack
The Druid ChatBot Portal allows you to create the bot once and deploy it in Slack.
Prerequisites
- You built and published a Druid chat bot.
- You have a Slack account.
This section describes how to integrate a Druid chat bot with Slack.
Step 1: Create a Slack application for your bot
- In your browser, sign in Slack.
- Navigate to Your Apps panel.
- Click Create New App or Create an App (if you have no other apps). A pop-up appears.
- Choose how you want to configure your app’s scopes and settings.
- In the App Name field, enter the name of your Slack application.
- From the Development Slack Team drop-down, select the name of your development team. If you are not already a member of a Development Slack Team, create or join one.
- Click Create App.
- Go to Your apps and click on the Slack app you created for the Druid chatbot integration.
- Scroll-down to the App details section and get the following details: Client ID, Client Secret and Signing Secret. Copy / paste them in a document, you will need them at Step 2.
If this is the first Slack app you build the Your Apps page will look like this:
We choose to configure from scratch. If you choose to configure from an app manifest, skip step 5.
A new pop-up appears.
If your app needs special scopes, follow step 2.
Step 2. (Optional) Add special scopes and generate Bot User OAuth Token
A Slack app's capabilities and permissions are governed by the scopes it requests.
If your Slack app needs special scopes which require Bot OAuth Token (which will be used in Druid in Slack channel configuration), for example to transmit Microsoft files, you need to define the specific bot token scopes and generate OAuth Token for Your Workspace.
To do so, follow these steps:
- In Slack, select the app and on the Features menu, click OAuth & Permissions.
- Scroll down to the Scopes section and under Bot Token Scopes, click the Add an OAuth scope button.
- Select the desired scope(s) (e.g., files:read).
- Scroll up to section "OAuth Tokens for Your Workspace" and click the Install to Workspace button.
- Allow the app to access your workspace.
- Copy the Bot User OAuth Token that was automatically filled in.
Step 3. Activate the Slack Channel
- In the Druid ChatBot Portal go to your bot settings. Click the Channels tab, then click Slack. The Slack Channel Info section expands.
- Enter the Client Id, Client Secret and Signing Secret of your Slack app, the one copied at Step 1.
- (Optional!) If you want your bot to perform actions that require Bot OAuth Token, in the Bot User OAuth Token field, enter the value copied from Slack app.
- Click the Publish button. The channel activation might take up to 1 minute. When the channel activation completes, the OAuth & Permissions Redirect URL, Event Subscription Request URL and Interactivity Request URL fields are automatically filled in. Copy the three values, you will need them at Step 3.
After the channel’s activation, the following fields are available in DRUID:
- [[ChatUser]].ChannelId = "slack"
- [[ChatUser]].UserId - Stores an unique identifier of the Slack user account.
Step 4. Configure your Slack app
Add a new redirect URL
- In Slack, navigate to Your Apps panel and click on your app.
- On the left menu, click OAuth & Permissions and scroll down to section Redirect URLs.
- Click Add a new Redirect URL.
- In the box, enter the OAuth & Permissions Redirect URL copied from the Druid ChatBot Portal (at Step 2) and click Add.
- Click Save URLs.
Set up the app interactivity in messages
On the left menu, click Interactivity & Shortcuts and tap on Interactivity.
In the Request URL field, enter the following URL: https://slack.botframework.com/api/Actions. This is the Interactivity Request URL automatically generated in Druid after you published the Slack channel. The value is generic for all bots.
Click Save Changes.
Subscribe to Bot Events
By subscribing to bot events, your app will be notified of user activities at the URL you specify.
Follow these steps to subscribe to six specific bot events:
- On the left menu, click Event Subscriptions and tap on Enable Events.
- In Request URL, enter the Event Subscription Request URL copied from the Druid ChatBot Portal (at Step 2).
- In Subscribe to Bot Events, click Add Bot User Event.
-
Search for and select these six event types:
- member_joined_channel
- member_left_channel
- message.channels
- message.groups
- message.im
- message.mpim
At the bottom of the screen, click Save Changes.
As you add events in Slack, it lists the scopes you need to request. The scopes you need will depend on the events you subscribe to and how you intend to respond to them. For Slack supported scopes, refer to Scopes and permissions. See also Understanding OAuth scopes for Bots.
Allow users to send Slash commands and messages from the messages tab
From the Features menu, click App Home and scroll down to the Show Tabs section.
Tap on Messages Tab and tick Allow users to send Slash commands and messages from the messages tab.
Step 5: Add app to Slack workspace
From the left menu, click Basic Information and in the Install your app section, click the Reinstall to Workspace button.
Click Allow to grant the Slack app access to your Slack workspace.
The app appears in Slack on the left menu under Apps. You can now successfully use the Druid chatbot in the Slack messaging platform.
Talk to the bot in Slack channels
To talk to the bot in a Slack channel, you need to add the bot to the channel:
- Select the Slack Channel.
- Click the drop-down arrow next to the channel name to open the channel settings.
- Click the Integrations tab.
- Click Add an app.
- Select the bot from the list to add it to the channel.
To interact with the bot, start your message with @<bot name> to ask the bot something. This will create a thread within the channel where you can continue the conversation.
Each thread has a unique conversation ID in DRUID that stores the thread conversation in the Conversation History.