3. Deploy your chatbot on Slack

Romil Jain
4 min readApr 4, 2019

If you would have reached this far, I assume you must have already gone through my previous articles Build a Conversational Chatbot with Rasa Stack and Python — Rasa NLU & Rasa Core. If not then I would recommend you to go through those first to get the better idea on this article as this is the third and the final part of the trilogy of building a conversational chatbot with Rasa.

Quick Recap — What we have achieved so far

In part-1, We put our efforts to understand the Rasa Natural Language Understanding (NLU). We trained our bot with some sample messages so that they can understand the intent and extracts the entities and create some structured data.

In part-2 we learned more on Rasa Core which is really the core part of the bot. The structured data from Rasa NLU is fed into Rasa Core and we trained the bot to take some actions and respond to the user messages. We created stories, templates and some custom actions for the bot to respond intelligently.

Now our bot needs some interface to chat with the user and for that we chose Slack. In this final part, we will focus on deploying our bot over slack and use its interface to chat with the bot and train it more.

Deploy Bot on Slack

Before we do the slack setup lets first install ngrok.

What is Ngrok?

Ngrok is multiplatform tunneling, reverse proxy software that establishes secure tunnels from a public endpoint such as the internet to a locally running network service while capturing all traffic for detailed inspection and replay. In short, It is a tool that allows you to create a “tunnel” from your localhost to the internet with one simple command. So basically the app running on our local would be available via the internet publicly.

· Download the ngrok from here.

· Make sure to create an account to get the auth token.

· Follow the steps provided to fire it up (ngrok http <port>)

If everything goes well then you will see below on the screen ( I used the port 5004 for our bot integration)

ngrok

https:// — — — .ngrok.io is the ngrok URL which we would be using shortly.

Now let's do the slack setup

Slack Setup

To deploy the bot on Slack

· Create a workspace or use an existing workspace if you have any on Slack. I created a new Workspace ‘Bots’

· Create an app via https://api.slack.com/apps to deploy the bot as shown below. The name of my app is Wall-E

Slack setup

As shown above, make sure to add i) the bot user and ii) upload the picture, provide a brief description and a background color

Save all the changes and finally, before installing the app into the workspace, click on event subscription, add the ngrok URL https://------.ngrok.io/webhooks/slack/webhook to request URL and subscribe to Bot events as shown below.

Now install the app on the workspace and get the Bot User OAuth Access Token which would be required in our bot application to connect with Slack.

Deploying the Bot on Slack

To deploy bot on slack we need to do some modification in the existing code.

a) First, create a credentials.yml file in the project root directory i.e wall-e

$ cd wall-e
$ touch credentials.yml

And add below lines

slack:
slack_token: "<Bot User OAuth Access Token from the slack app>"

Now pass this slack token to dialogue_model.py created in the last part and add below lines of code in run_core (Check the port ‘5004’ here. It's the same port which while firing the ngrok above)

input_channel = SlackInput(slack_token)
agent.handle_channels([input_channel], 5004, serve_forever=True)
dialogue_model.py

Time to chat

Now its time to run the code and chat with bot over the slack interface.

## make sure ngrok is already up and running on port 5004## Train and Run CORE
$ python3 dialogue_model.py
## In the new terminal run custom action
$ python3 -m rasa_core_sdk.endpoint --actions actions
Chat with Wall-E

In case you landed up to this article directly, I would highly recommend going through the earlier articles on Rasa NLU and on Rasa Core.

If you need complete code, it is available here on GitHub.

Please share your thoughts, feedback, comments, and clarifications. It will help me to improvise.

If you liked this post, you can help me share it by recommending it below ❤

Follow me on Linkedin and Twitter

--

--