In this series 3 of the blog post on how to build a secure AI Chatbot using RASA and Python, we will learn how to deploy the chatbot: “Trippy” on Slack.

How to Build Best AI Chatbot: What did we do in Part 1 & Part 2?

If you haven’t read part 1 and part 2 of this blog, you can read it here in the blogs: chatbot using RASA and AI chatbot using RASA & Python. In the first part, we discussed in detail the RASA framework. Using the RASA NLU component of the framework we started coding “Trippy: The Travel Agency Chatbot”. In Part 2, we learnt how to use the concept of Stories, Domain and Custom Actions to code our travel agency chatbot Trippy. So far, our chatbot Trippy is able to interact with the user using the RASA shell. Here is a snippet of the same:

best-ai-chatbot-using-rasa-python-1
Tippy interacting with user using the RASA shell

How to Build Best AI Chatbot: Objective of Part 3?

In this part, we will deploy the chatbot on Slack. It is therefore recommended to complete Part1 and Part2 before attempting Part3. Additionally, we would need to create an account on Slack and do some integration settings there as well. 

Inspired by this analysis and want to learn how to do it / wish to replicate this for your project? We can help you there. Just leave your email address in this google form and we will share the analysis with you within 48 hours.

Creating Slack App

1. Login to your slack account and go to https://api.slack.com/

2. Select an existing workspace or create a new one for Trippy.

3. Create a new App by giving it a name and selecting the workspace: 

best-ai-chatbot-using-rasa-python-2
Slack Snapshot

Please note, in the second dropdown, the workplaces linked to your account will appear. 

4. A lot has changed with the Slack Api in recent times, so you may want to visit https://api.slack.com/authentication/basics first in order to make yourself familiar with the functionalities and features we are going to add to the app we created in Step 3. 

5. Go to the OAuth & Permissions sidebar, in the Scopes section click on Add an OAuth Scope. Add the following scopes to the “Bot Token Scopes”.

best-ai-chatbot-using-rasa-python-3

6. Install the App to your workspace by clicking on “Install App” in the settings section. 

best-ai-chatbot-using-rasa-python-4

Click on “Allow”. The page will show you “Bot User OAuth Access Token” . Copy the token (for Step 9). Please do not share this or check-in the version control system. 

7. Go to “App Home” in features and edit any details that you want to. Switch on the “Always Show my Bot as Online” feature.

best-ai-chatbot-using-rasa-python-5

8. Go to your Slack channel, right-click and “copy link”. The last part of the link in the channel id. We will need this in Step 9. 

For example, C013CTG7T9P is the channel id: 

best-ai-chatbot-using-rasa-python-6

9. Edit the credentials.yml file in the trippy_2 folder and provide the details in the slack section:

best-ai-chatbot-using-rasa-python-7

10. If you are running this code on a local machine which does not have a registered domain name, you would need to install and run ngrok. You can read more about installations and features of ngrok here.

>> ./ngrok http 5005

Code-snippet

You can see that ngrok has mapped the localhost:5005 to a .ngrok.io address. We now need to use this mapping to configure the slack app.

11. Start the chatbot using the rasa run command:

best-ai-chatbot-using-rasa-python-9

12. Go to the Slack App page and subscribe to events by giving the ngrok url appended by /webhooks/slack/webhook. You should see the Verified message. Else there is some issue with your setup. 

Converstaion-on-Slack
Source: Slack

13. Subscribe to the at least the following Events:

Converstaion-on-Slack-2

14. Also, ensure that the action server is running as well. 

Inspired by this analysis and want to learn how to do it / wish to replicate this for your project? We can help you there. Just leave your email address in this google form and we will share the analysis with you within 48 hours.

Let’s Chat with Trippy!!

Well, that was a lot of configuration. If you have successfully followed so far, Well Done!! Finally, we can now interact with Trippy from the Apps in Slack. 

Chatbot-Converstaion-on-Slack
Snapshot of the Conversation with an AI Chatbot “Trippy” on Slack

You can also chat by sending direct messages to Trippy @trippy in a channel:

Converstaion-on-Slack-1
Snapshot of the Conversation with an AI Chatbot “Trippy” on Slack

This was an exhaustive series of blogs on “How to build a Secure Chatbot using RASA & Python”. In part 1 we built a simple NLU bot capable of understanding intents and entities. In part 2 we scaled up the bot with dialogue management and custom actions. In this part 3, we deployed the bot and connected it to a fully functional Slack App. You can follow the same process and connect your Rasa Bot on the platform of your choice. The Rasa framework supports a wide variety of messaging platform.

An important thing to note is that we did all this with very little python code and that too was related to the functionality of the bot. We did not write the scaffolding code to connect and pipe either. Well, that is one more reason why we chose the RASA framework for building the chatbot. To get access to the complete code and configuration files, please fill this form to send us the request and we will share the analysis with you within 48 hours. Springboard’s courses on machine learning provide excellent learning opportunities and understanding on NLP and ML that comes with a 1:1 mentoring-led and project-driven approach along with a job guarantee.