Advanced Guide: How to Create a Chatbot in Telergam

Learn, share, and connect around europe dataset solutions.
Post Reply
subornaakter20
Posts: 279
Joined: Mon Dec 23, 2024 3:42 am

Advanced Guide: How to Create a Chatbot in Telergam

Post by subornaakter20 »

From a technical point of view, when you launch a chatbot for Telergam on your device, you activate an application that sends requests to the Telegram Bot API. The API is very simple here, the request goes to the desired URL with the specified parameters, and the response from Telegram comes as a JSON object.

Instructions for advanced users

Source: fizkes / shutterstock.com

This will be clearer if we consider the API hospital contact list operation using a specific example. Here is the order of steps to make the simplest chatbot for Telergam:

Application registration
This is the initial stage that you must pass. During the registration process, you receive a personal id (which is also a token) from a special bot responsible for this procedure (@BotFather).

Send a message /start to @BotFather and in response you will receive a list of commands available for use.

Start with the main one, namely - /newbot. After receiving it, the program will offer to create a name for the new robot. You can choose absolutely any name, but at the end there must be the word "bot". If everything went well and quickly with the name, a token and a link will come from @BotFather, by which you add the bot to the list of contacts.

So, the beginning has been made. Already at this stage, the functions of attaching an avatar, greeting and description become available.

Experience shows that the received token may not work correctly, so it is better to check it immediately. To do this, use the special link api.telegram.org/bot<TOKEN>/getMe.

The programming process
In this example, the program is created using Python3. Then the written algorithms can be transformed using any other language, Python3 allows it.

When programming a chatbot for Telergam, you don't have to manually send each message — webHook can do it for you (you just need to install it). In the case of Python, it's best to use one of the existing editors (then the problem of fiddling with cgi and streams disappears). In this particular example, everything is done using tornado.web. Tip: a convenient bundle for GAE is Python2+Flask.
Post Reply