3 horizontal lines, burger
3 horizontal lines, burger
3 horizontal lines, burger
3 horizontal lines, burger

3 horizontal lines, burger
Remove all
LOADING ...

Content



    How to get telegram bot token via bot father

    Clock
    14.01.2025
    /
    Clock
    02.10.2025
    /
    Clock
    2 minutes
    An eye
    4242
    Hearts
    0
    Connected dots
    0
    Connected dots
    0
    Connected dots
    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
    Ideally, it would be better to save it in an environment variable. After all, to get to the virtual environment variable, you will first need to get root rights on the machine and then activate the virtual environment.

    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:
    1. Create a bot, /newbot
    2. View created bots, /mybots
    3. Delete bots, /deletebot
    4. 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:
    1. enter the /mybots command
    2. select your bot
    3. select Bot settings
    4. click on Inline mode
    5. 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:
    python -m venv .venv
    Activate it and install the necessary packages:
    .\.venv\Scripts\activate pip install aiogram pandas babel
    Packages that I install by default:
    1. aiogram: de facto the only package that we need. It will allow you to communicate with the telegram API using only asynchronous calls.
    2. pandas: for working with documents, not required
    3. 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. ж)

    Do not forget to share, like and leave a comment :)

    Comments

    (0)

    captcha
    Send
    LOADING ...
    It's empty now. Be the first (o゚v゚)ノ

    Other

    Similar articles


    How to deploy(host) telegram bot on vps

    Clock
    19.01.2024
    /
    Clock
    05.10.2025
    An eye
    7016
    Hearts
    1
    Connected dots
    0
    Connected dots
    0
    Connected dots
    0
    It is a guide for deploying a telegram bot on VPS. This bot will be written in Python/aiogram. Also you will know how to install, run, and update it. As …

    How to turn on the telegram bot’s inline mode, and how to build one

    Clock
    10.01.2025
    /
    Clock
    02.10.2025
    An eye
    3832
    Hearts
    0
    Connected dots
    0
    Connected dots
    0
    Connected dots
    0
    How to implement an inline telegram bot or activate inline mode for an already existing Telegram bot and how to use it. The entire example code is available, and the …

    How to add translations(localisation) for your telegram bot in aiogram/python + i18n

    Clock
    14.01.2025
    /
    Clock
    02.10.2025
    An eye
    1622
    Hearts
    0
    Connected dots
    0
    Connected dots
    0
    Connected dots
    0
    In this article, I will show you how to make translations(localisation) for telegram bots made in aiogram/python. And I will do it using the Babel (+ i18n) package. You will …

    Used termins


    Related questions