Telegram Bot API & how to generate Auth token

What is a telegram bot?

A telegram bot is basically a program which is designed with a sole purpose of the interaction, it is a program which can interact among systems and users using them. We can have a clear understanding of a telegram bot by considering an example, suppose we are facing certain issues in our TV channels which are broadcasted by some XYZ company, now whom should we contact? Should we contact the owner of the company? Obviously not! We

will call the customer care helpline about the issue we are facing, and we want to fix it as soon as possible, and he/she will do it for us, right? Similarly, a telegram bot also interacts within the networks and makes the work done for us. 

So, we can say that a telegram bot is a third-party application that runs inside the telegram app. Here the question arises how can we interact with bots? We can interact with them by simply writing appropriate commands as messages in chat with our bot.

However, we can say that telegram bots are special accounts that do not require an additional phone number to set up. They can be accessed by us in two ways :

  • By adding them to groups or by opening a chat with them to send messages and commands.
  • For directly sending content from inline bots into any chat, group or channel we can type bot’s @username and a query.

Need of Telegram Bot API:

The bot is accessed over the servers by using the uniquely generated token which is the API Key here. The bot name given is only for a user-friendly interface as it will be very inconvenient for the user to use the token every time. The Bot API is an HTTP based interface created for developers having a keen interest in building bots for telegram. This API allows us to easily create programs that use Telegram messages for an interface. It allows us to build our customized projects.

Generating Telegram Bot Auth. Token:

A token is a string or line consisting of letters and numbers which is require in order for authorizing the bot and for sending requests to the Bot API. One should try to keep it safe but if in some cases.

it is anyhow compromise one can generate a new token just by typing \token.

Here are some simple steps to follow and you are ready to go:

First, open the telegram app and make sure that you are at the home screen. 

  1. On the Home screen of the app, click on the search icon on the top right and search by the name “botfather”. We can create a new bot in telegram with the help of a bot called ‘BotFather‘. So, basically BotFather is a single bot to rule all the other bots. It can create a new bot as well as it can modify the older ones.
  2. In the search results, there will be many bots by the same name but be cautious while clicking on the correct result for “BotFather” as shown below. The correct “BotFather” will have a tick mark next to its name. Once you click on the correct botfather, you will directly driven to a chat window with the “BotFather”.

3. The chat will have a few items already by default and will display you a list of commands. So get start, by clicking on the start tab at the bottom of the window as shown below.

4. Once you have clicked on the start tab a message similar as shown below will arrive at your chat from the BotFather; which will consist of various commands for specific operations.

5. After receiving a similar message as shown above since we are going to create a new bot, we need to type the command  /newbot as shown below. 

6. Now it will be asking you some more details, at first it asks you for a bot name, so give a name of your choice by which you would like to call it. For example:

7. After entering the bot name you will have to enter the bot’s username, and there is a certain restriction on it that the username must be ended by the word, ‘bot’.

8. Once you have entered a unique username it is all set and you are done with generating the Auth. Token. Keep the token safe as it will be used in the code to access HTTP API. 

Summary

Now, since you have completed all steps described above, you must have received your token, so, for now, you are done but the purpose of generating the token starts here because now you can create a channel and add your bot in it for future requirements and you can also include this uniquely generated token in the code wherever you need.

Written By : Priyanshi Omer
Reviewed by: Batta Pruthvi

If you are Interested In Machine Learning You Can Check Machine Learning Internship Program
Also Check Other Technical And Non Technical Internship Programs

Leave a Comment

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