Integrating Telegram with Rasa Chatbot

Automation…Automation… Automation… 🤖

Automation has lead to the success now a days. All the businesses that are run online have grab the opportunity to automate it’s service to grab more audience attention.

Also with the automation you are providing the customer a service for 24*7 which is a very good initiative for your businesses to give more and to earn more. To expand your businesses I’m here with this session to make you learn this amazing technology to integrate it into your businesses to earn more revenue.

In this session, you will learn how to integrate telegram with Rasa chatbot and to make your bot as a contact in telegram as an assistant to communicate with it. for example to get the solutions to your queries, to book a cab through texting, to enquire the queries related to your business, etc.

Also you will how to share your telegram bot with anyone so that it can be send worldwide for production.

Firstly we will build a basic chatbot that will work in action when we will connect it to the telegram. In my case, I already have a chatbot ready with me and I’ve shared it on my git repository and you can also download the code from there. To get the full code of the working of this chatbot then checks this link:

https://github.com/ashus3868/RasaCustomerService.git

If this is your first blog from me then do check this link as well to learn how to build your own Rasa chatbot the checkout this link :

https://www.youtube.com/playlist?list=PLtFHvora00y8NBwCMoNnPqii-y2-gyl5p

Now, I assume that you have your working chatbot with you and we can proceed to integrate it to telegram. Firstly,you have you download the basic applicationof telegram from app store as per the smartphone you are using.

After downloading the application on your smartphone signups/login to telegram first. After logging in click on the search icon on the top right corner in your application and search for BotFather and select it.

When you have selected “BotFather” follow the instructions as shown here:

From the video above it will be very clear to you that how to get the credentials from telegram that are required by Rasa chatbot to integrate with telegram. Now you you have the access token and Verify id with you. So you can add then to the credentials file in your Rasa project to integrate then together.

Now, open your Rasa project and go to credentials.yml file and add the following lines to it.

telegram:
  access_token: "490161424:AAGlRxinBRtKGb21_rlOEMtDFZMXBl6EC0o"
  verify: "your_bot"
  webhook_url: "https://your_url.com/webhooks/telegram/webhook"

In the above lines of code access_token and verify, you will get it from telegram BotFather while setting up the bot and in webhook_url you will have to add your domain url. If you don’t have any domain with you then you can use ngrok for now to make your localhost url to set as global url to integrate and communicate with telegram.

Checkout this video to learn how to use ngrok to set the bot to production or lets say globally:

Now when you have your ngrok link with you, replace it in webhook_url to set it for global.

After the setup, go to terminal and activate your Rasa environment where you have all the packages already installed. Run two separate terminal with this environment and parallely type the commands shown here:

rasa run
rasa run actions

When these two commands are running parallelly you can now run open the bot from the link provided by BotFather and start chatting with the bot.

Now your bot will be in action.

To learn and view the complete concept practically you can check this video:

If you are new here and don’t know much about python programming so you can learn python here. To learn python programming check out this link:

For any doubts or queries related to the topic, feel free to leave a comment below in the comment section. Also do comment your valuable feedback in the feedback so as to appreciate or improve ourselves. For any further information or queries you can also WhatsApp me at +91 8209829808.

Till then stay tuned and happy learning 🤗

One thought on “Integrating Telegram with Rasa Chatbot

Leave a Reply

Your email address will not be published. Required fields are marked *