Create a Telegram chatbot with Google’s Dialogflow!

Marcus Yatim
5 min readJun 2, 2021

Creating a chatbot on Telegram can be really fun and is actually a rather simple task. Whether you want to create a chatbot for professional usage in your startup business, or maybe you’re feeling bored and want to have a conversation (society recommends going out to socialise but, hey, not all of us are vaccinated against coronavirus at the moment), this introductory article shall get you started on some basic knowledge that you’ll need. As always, I also have a YouTube video covering the same subject for those of you visual learners.

Be sure to Like and Subscribe!

Areas of Research

The domain of interest that we are working on is called Natural Language Processing (NLP). NLP is an artificial intelligence domain that deals with how the computer tries to understand, decipher and process the natural languages of humans, be they in written or verbal format. A chatbot utilises NLP in order to interpret the input of the user and give a response accordingly. Of course, this input is not in the form of lines of codes, but instead in natural written/spoken words.

We will be enlisting the help of two free* tools: Google’s Dialogflow and Telegram’s own bot, the BotFather.

*Pricings may differ from time of writing of this article.

Dialogflow

Google’s Dialogflow is a top notch NLP solution. It is part of the Google Cloud line of products and there are two editions, the Dialogflow CX and the Dialogflow ES. The CX Agent is more advanced and has a larger suite of capabilities. Both have different pricing tiers and at the point of this writing, only the ES Agent has a free trial. We will be using the free trial version of the ES Agent for this project. For more information, visit https://cloud.google.com/dialogflow.

BotFather

To create a bot on Telegram, there is, very aptly, just a bot for that: BotFather. The BotFather contains simple and intuitive steps that will guide you through in creating your first bot. There are many different types of bots that you can create, including a payment bot, a gaming bot and of course, a chatbot. To find out more about Telegram’s bots, visit https://core.telegram.org/bots. We will dive further into how to specifically create a chatbot in the later sections.

Prerequisites

This article does not actually require you to posses any coding skills. All of the steps required to actually create a rudimentary chatbot on Telegram can be done so via various GUIs. Of course, it is possible to include your own code to create a more robust and feature filled chatbot. However, we will not be going through any coding for the purpose of this introductory tutorial. If you would like to read more on a chatbot I created that involves coding and Google Maps API implementation, you can always find it on this other medium article.

Knowledge on machine learning, artificial intelligence and NLP would also be useful in gaining a greater appreciation for the work that we shall embark on. If not, I hope this article could serve as a good starting point for your learning journey.

This article will also assume you have the necessary requirements for setting up Dialogflow and Telegram, e.g. a Google account, Telegram account, etc. In fact, I will also not be explaining in detail how Dialogflow works, because there already exists a very comprehensive documentation* provided by Google @ https://cloud.google.com/dialogflow/es/docs. However, the documentation is incredible long and with many sections, which may prove quite daunting or confusing for a beginner. Never fret! As I will help you navigate through the documentation in the next section.

*The contents and/or arrangement of the documentation may be subjected to change as Google continually upgrades itself. I will do my best to revise my article according to any changes, however, I cannot guarantee that the article will be kept up-to-date always. I do apologise for any inconvenience. Kindly leave a comment below if you do notice any discrepancies. Thanks in advance!

Getting Started with Dialogflow

1) Firstly, I want you to start at the main page of the documentation @ https://cloud.google.com/dialogflow/es/docs.

Step 1

At the very top, you should notice a “GO TO THE DIALOGFLOW ES CONSOLE” button highlighted in blue. Click on that link (or just follow here https://dialogflow.cloud.google.com/). Go straight to your console that you have just opened.

Step 2

2) This step will assume that you have set up your Google Cloud account and accepted all its terms of service. Now, we can get straight to some hands on work. Refer to https://cloud.google.com/dialogflow/es/docs/quick/build-agent and follow the guide closely, starting from ‘Create an agent’. Once you have created your agent, you are going to notice a toolbar on the left with a lot of unfamiliar terms, e.g. Intents, Entities, Fulfillment and Integrations, as seen in the image on the left. (Ignore the name ‘COVIDChatbot’, that was from a previous project I did). Before moving forward, we should understand what these terms actually mean. To do that, we can refer to https://cloud.google.com/dialogflow/es/docs/basics to explain everything we need.

3) Once you have understood all of that, you can return to the “Build Agent” guide. Run through the rest of the entire page to create your agent.

Congratulations, you have just created your first fully functioning agent! You do not need to continue on to the ‘Fulfillment’ section for the purpose of this project, but, feel free to check that out as well.

Connecting Dialogflow with Telegram

We are now ready to connect our Dialogflow agent with Telegram. This will be a simple procedure and thankfully, Google has also provided a comprehensive guide for it @ https://cloud.google.com/dialogflow/es/docs/integrations/telegram. Follow the guide to the end.

Congratulations! You have your very first Telegram chatbot!

Conclusion

That wasn’t so tough, wasn’t it? And we have only scratched the surface. There are many other functions, both on Dialogflow and BotFather, that we have not explored. A lot more reading and learning can be done on the Dialogflow documentation itself that can help you create an even more robust NLP chatbot.

--

--

Marcus Yatim

Innovator. Challenging the norms. Avid content creator.