In this blog, you will learn,
1. How to create a channel on slack
2. How to integrate Rasa chatbot to Slack
3. How to accept widgets from rasa chatbot and to display on slack channel
To demonstrate this with slack bot I’ll use one of my previous chat-bot cum voice bot which I have already shown before. But this time I’ll use that chatbot to show you the more advanced level of chatbot that can interact with you with the most likely used channel(Slack) by the professionals. Now, lets understand this in more details and let’s create our own slack bot. You can download the full code for the Subscriber count chatbot from here.
How to create a SLACK CHANNEL
To create and link your own chatbot on slack channel go to https://api.slack.com/apps and follow the steps below for slack channel:
Step 1: When you will go to this url you will see multiple apps if you have already created some otherwise you will get an option only to create new app. Just click on it to create a new app as shown below,\
Step 2: When you will click on create new app, you will get be asked to enter the app name and the namespace to use as shown here. Fill them and click on create app.
Step 3: Now you will get the basic information about your app that you just created. Here, you have to go to add features and functionality and select Incoming Webhooks . Once you are in, you will see an option Activate Incoming Webhooks which is bydefault Off, you have to turn it On to activate it for the proper functionality of the webhooks.
Step 4: After this step you have to go to Interactivity & Shortcuts, after this you will be taken to the other page where you have to first turn the interactivity On which is Off bydefault as shown here.
Step 5: In the above image you can see after the interactivity option is turned On it is asking you for the requested url on which your chatbot will is live. If you already have a server on which your chatbot is live then add the url for it otherwise use ngrok for it and add the link in the Requested URL box. The URL will look like this,
In the above link you have to replace your server IP or domain at the place of website/ngrok-url. When you are done with this click on save changes to save everything.
Step 6: Now click on Oauth & Permissions which will open the new page for you where you will find a button to Install App to workspace which will generate the Oauth tokens that will be used later to add to the credentials.yml to link your rasa chatbot to the slack channel. After you click on Install App to Workspace you will be redirected to the page to select the channel on which you want to talk to your live rasa chatbot. To complete this step you must first have a channel already connected so that you can link it here. If you already have it then select the one otherwise create one and come back to this page.
Like in my case I already have one so I’ve directly selected it as you can see above. After the successful connection of the channel you will get the Oauth token as shown here:
Now, copy this token and add this to the slack credentials of your rasa chatbot. Also on the same page you will find and option for the Redirect URLs, here you have to add the same url that you added before in step 5 and after that add it and save it.
Step 7: Now, scroll down on the same page and go to Scopes > Bot Token Scopes > Add an Oauth Scopes , Here just type chat:write and add it so that it can be linked to your chatbot to send and receive the messages. After you will add it. It will ask you to reinstall the app. Click on it to reinstall the app just like we did before in step 6.
Step 8: Now go to Event Subscriptions and turn on the Enable Events option to listen to the chatbot in real-time like its shown here,
Here you have to add the same url which you added in the step 5 and then click on Verify. But make sure before you click on verify your chatbot should be actively running and you have added the slack credentials correctly. To make it run live on your local system with ngrok, go to the project directory on the terminal and execute the given commands,
Run the action server in parallel to take the dynamic actions.
rasa run actions
Add the slack credentials like shown here,
slack: slack_token: "<Oauth-tokens>" slack_channel: "<channel id>" slack_retry_reason_header: "x-slack-retry-reason" slack_retry_number_header: "x-slack-retry-num" errors_ignore_retry: None
Once it is running live and you have added the credentials properly, verify it to check the proper functioning of the webhook api for the slack channel. Now scroll down and go to Subscribe to bot events > Add Bot User Events and now add the given events: message.im, message.groups, message.channels and message.mpim. FInally click on save changes to save all. Now it will again ask you to reinstall the app which is really important so just reinstall the app like you did in step 6.
Step 9: Now go to Incoming Webhooks and scroll to Webhook URLs for your workspace. From here just copy the curl command and run it locally on the terminal only for the first time. After that goto the slack channel that you connected to the rasa chatbot for communication.
From here you can go to the app like shown below,
Everything is done successfully and now you can talk to the bot here and use it to expand your business model.
In the above image you can see how your bot is replying to you and how you can it can be useful you. If you still have any doubts in your mind then you can also check this video for more clarification.
For any doubts or queries related to the Integration of rasa chatbot to slack channel, feel free to leave a comment below in the comment section. Also, do comment your valuable feedback to appreciate us. For any further information or queries, you can also WhatsApp me at +91 8209829808.
Stay tuned and happy learning. 😉