
Initial set up for telegram bot
14.01.2025
46
0
0
0
0
Introduction
This is a basic article, you will see how to get a token for a bot and how it can be used. Also, we will talk about the various possible bot settings and what they can be used for.
Getting a token
To get a token, you need to contact the father of all telegram bots, BotFather. Enter the command /newbot and do what he asks (that is, enter the name of the bot and its name with the prefix bot).

Something like this ...
He will reply to you with a link to a chat with a new bot and its token. Save the token in a separate file. I usually call such a file .token. The file will have only one line, instead of TOKENMOI insert your token:
BOT_TOKEN=TOKENMOI
An example:
BOT_TOKEN=1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Setting up bot
In the chat with BotFather, we can manage our bots, applications, and games. But we are only interested in bots, you can do the following:
- Create a bot, /newbot
- View created bots, /mybots
- Delete bots, /deletebot
- Edit bots, /editbot (add descriptions, change the name, edit commands...)

An example ...
In particular, we can activate inline mode for the bot. That is, a mode in which you can contact the bot from any chat, and it will return some answer to the current chat.
Activating Inline mode for a bot
To do this, in a chat with the same BotFather:
- enter the /mybots command
- select your bot
- select Bot settings
- click on Inline mode
- Turn on (enable)

From 1st to 3d step

4th step

5th step
Create a virtual environment and install python packages
Now it's time to create a virtual environment and install packages. Create a directory where all the files from the bots will be. Move the file with the bot token there (.token file), then create a virtual environment:
Activate it and install the necessary packages:
Packages that I install by default:
- aiogram: de facto the only package that we need. It will allow you to communicate with the telegram API using only asynchronous calls.
- pandas: for working with documents, not required
- babel: for translations, not required, but highly recommended.
Conclusion
All my bots have one beginning, and here I described it. Next you need to write the basic functionality for the bot, handlers, routers, and connect to databases or create your own. It will be different for different bots, but the beginning is the same for all, and it is here. ж)
Comments
(0)
Send
It's empty now. Be the first (o゚v゚)ノ