Connect a Microsoft Azure Bot to Slack Channel

Connect an Azure Bot to Slack Channel. There are two ways to achieve this. The one is using the Azure portal and another one using the Slack adaptor.

We will use the first approach as it is easy and our bot is already deployed to the Azure portal. In another post, we will look at the second approach.

Prerequisites

  1. Microsoft Azure Account
  2. Deploy a Basic .NET Core Bot to Azure using Visual Studio
  3. Slack Account
  4. Permission to access Slack workspace to create and manage applications

Create a Slack Application

Go to My Apps in Slack. Click on Create an App.

Choose the option to create the app from scratch.

Enter the name of your slack application, I will give FlightBookingApp. Also, pick a workspace where you want to develop this app. Click on Create App.

When your app is created, you will see a similar screen where your app is selected from the dropdown.

Add a new redirect URL

In the left menu, click on OAuth & Permissions. The option is available under Features.

Scroll down to Redirect URLs. Click on Add New Redirect URL.

In the input box, give the following Redirect URL – https://slack.botframework.com/. Click on Add.

Make sure to Save the URLs. When saved, the button colour will change to Grey from Green.

Subscribe to bot events

Your app can subscribe to be notified of events in Slack (for example, when a user adds a reaction or creates a file) at a URL you choose.

In the left menu, click on Event Subscriptions. The option is available under Features.

Enable the Events by toggling to the on button.

Enter the request URL. It is in the format of https://slack.botframework.com/api/Events/{YourBotHandle}. Replace the {YourBotHandle} with the value of your bot handle. It is available in Azure Portal. The bot handle is the name of your Azure Bot resource.

My bot handle name is AlexaFlightBot. You can also get the request URL from Azure Bot Resource -> Channels -> Slack -> URLs.

Copy the Event Subscription request URL and paste it into the Slack request URL input box.

Open the Subscribe to Bot events and click on Add Bot User Event. From the list of events, choose the below 6 events and save the changes.

  1. member_joined_channel
  2. member_left_channel
  3. message.channels
  4. message.groups
  5. message.im
  6. message.mpim

Enable sending messages to the bot by the users

In the left menu, click on App Home. The option is available under Features.

Scroll down to find the Show Tabs. Inside the Messages Tab check the box Allow users to send Slash commands and messages from the messages tab.

Add and configure interactive messages (optional)

In the left menu, click on Interactivity & Shortcuts. The option is available under Features.

Turn on the Interactivity and enter the following Request URL and click on Save Changes – https://slack.botframework.com/api/Actions.

Configure your Bot Slack Channel

First, you need to gather the Slack app credentials and then use them in Azure to configure the Slack channel.

To gather the Slack app credentials, click on the Basic Information tab under Settings.

Scroll down to App Credentials. Copy the Client ID, Client Secret and Signing Secret.

To configure the Slack channel in Azure, go to your Azure Bot resource, click on Channels, select Slack from the list of channels. Paste the above-copied values in their respective fields.

The landing page URL is optional. You can change it if required. Click on Save to make changes to your Slack channel configuration in Azure. A new tab will be opened, you will have to Allow giving permissions.

If you get this message – Channel validated, then you are good to go.

Test your Application in Slack

Log in to the Slack workspace where you installed your app. You will see it listed under the Apps section in the left panel. Just go to https://slack.com and log in.

Chat with your application to make sure it is giving the correct response.

Thank you All!!! Hope you find this useful.


Up ↑

%d bloggers like this: