Connect a bot to Slack
APPLIES TO: SDK v4
You can configure your bot to communicate with people through a Slack app. This article describes how to create a Slack app using Slack, connect your bot to your Slack app in Azure, and test your bot in Slack.
This article shows how to add a Slack channel to your bot in the Azure portal. For information on how to use a custom channel adapter, see Additional information.
Prerequisites
- An Azure subscription. If you don't already have one, create a free account before you begin.
- A bot published to Azure that you want to connect to Slack.
- Access to a Slack workspace with sufficient permissions to create and manage applications at https://api.slack.com/apps. If you don't have access to a Slack environment, you can create a workspace.
Create an app in Slack
You first create an application in Slack, which generates the information you need to configure the Slack channel for your bot in Azure.
- Go to Your Apps panel and sign in to your Slack account.
- Select Create New App, or Create an App if this is your first application.
- On the Create an app page, select From scratch.
- On the Name app & choose workspace page, for App Name, enter the name of your Slack application.
- For Pick a workspace to develop your app in, select a workspace for your app.
- Review and agree to the Slack API terms of service.
- Select Create App.
Add a new redirect URL
Once the app is created, add a redirect URL to your app.
Select OAuth & Permissions.
In the resulting pane, under Redirect URLs, select Add a new Redirect URL.
In the input box, enter one of the following redirect URLs and select Add.
- For a global bot, enter
https://slack.botframework.com
. - For a regional bot, enter following url according to the selected region:
Region Redirect URL Europe https://europe.slack.botframework.com India https://india.slack.botframework.com - For a global bot, enter
Select Save URLs.
Subscribe to bot events
After you add the redirect URL, subscribe your app to bot events to have Slack notify your bot of user activities at the URL you specify. Subscribe to events based on the features your bot will use in Slack.
Select Event Subscriptions.
In the resulting pane, toggle Enable Events to On.
For Request URL, enter one of the following request URLs, where
{bot-name}
is the display name for your Azure Bot resource, without the braces.- For a global bot, enter
https://slack.botframework.com/api/Events/{bot-name}
. - For a regional bot, enter following url according to the selected region:
Region Request URL Europe https://europe.slack.botframework.com/api/Events/{bot-name}
India https://india.slack.botframework.com/api/Events/{bot-name}
- For a global bot, enter
Under Subscribe to bot events, select Add Bot User Event, then subscribe to events. For example:
member_joined_channel
member_left_channel
message.channels
message.groups
message.im
message.mpim
Select Save Changes.
Enable sending messages to the bot by the users
After you subscribe to bot events, enable users to message your bot.
- Select App Home.
- In the resulting pane, in the Show Tabs section under the Messages Tab, enable Allow users to send Slash commands and messages from the messages tab.
Add and configure interactive messages
Optionally, enable interactive messages.
Select Interactivity & Shortcuts.
For Request URL:
- For a global bot, enter
https://slack.botframework.com/api/Actions
. - For a regional bot, enter following url according to the selected region:
Region Request URL Europe https://europe.slack.botframework.com/Actions
India https://india.slack.botframework.com/Actions
- For a global bot, enter
Select Save changes.
Copy your app information
You'll need the following information to add the Slack channel to your bot. Always copy and store app credentials in a safe place.
- Select Basic Information.
- In the resulting pane, under App Credentials, locate Client ID, Client Secret, and Signing Secret.
- Now, select OAuth & Permissions.
- In the resulting pane, locate the Scopes section. Record the Bot Token Scopes for your app.
Configure your bot in Azure
To complete this step, you'll need your Slack application credentials from the previous step.
Open the Azure portal.
Open the Azure Bot resource blade for your bot.
Open Channels and select Slack.
In Slack Channel Configuration, enter the information you copied in the previous steps.
- Enter the required Slack credentials for the application you created in Slack.
- Optionally, provide a Landing Page URL that Slack users will be redirected to after they add your bot.
- The OAuth & Permissions Redirect URL and Event Subscription Request URL values should match the values you entered in Slack to add the redirect URL and to subscribe to bot events.
Select Apply.
You're redirected to Slack to finish installing your Slack app.
- If the requested permissions look correct, select Allow.
Your bot's now configured to communicate with users in Slack. Users in the workspace can now interact with your bot via the Slack app.
Test your application in Slack
- Sign in to the Slack workspace where you installed your app.
- Under Apps, select your app.
- In the resulting pane, send messages to the application.
Additional information
Note
As of June 2020 Slack channel supports Slack V2 permission scopes, which allow the bot to specify its capabilities and permissions in a more granular way. All newly configured Slack channels will use the V2 scopes. To switch your bot to the V2 scopes, delete and recreate the Slack channel configuration in the Azure portal Channels blade.
For more information about Slack support for bots, see the Slack API documentation:
Connect a bot to Slack using the Slack adapter
As well as the channel available in the Azure AI Bot Service to connect your bot with Slack, the Bot Builder Community repos define a custom channel adapter for Slack.
- For information on the C# adapter, see the Adapters section in the .NET community repo.
- For information on the JavaScript adapter, see the Adapters section in the JavaScript community repo.