Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat blog/pythonda-telegram-bot-yaratish-aiogram-qollanma

Building a Telegram Bot in Python: A Hands-On Lesson for Beginners

Build a Telegram bot in 15 minutes with Python and the modern aiogram 3.x library. BotFather, getting a token, and working with commands and buttons.

Python Views: 19
Building a Telegram Bot in Python: A Hands-On Lesson for Beginners — cover image
Build a Telegram bot in 15 minutes with Python and the modern aiogram 3.x library. BotFather, getting a token, and working with commands and buttons.

In Uzbekistan, Telegram has become an inseparable part of daily life. Shopping, quizzes, news and almost every education service run through Telegram bots.

If you know the basics of Python, you can build your first working bot in just 15 minutes.

In this article we build a Telegram bot step by step with the modern aiogram 3.x library.


1. Register the bot with BotFather

  1. Open the official @BotFather bot in Telegram.
  2. Send the /newbot command.
  3. Give your bot a name (for example: Mening Birinchi Botim) and a unique username (for example: algor_sample_bot).
  4. BotFather will give you a special API token (for example: 7123456789:AAH...). Never show this token to anyone!

2. Prepare the environment and install the library

In your terminal, install the most popular asynchronous library, aiogram, into your Python environment:

pip install aiogram

3. The bot's code: main.py

Save this short, clean code to a file called main.py:

import asyncio
from aiogram import Bot, Dispatcher, types
from aiogram.filters import Command

## BotFather bergan token
TOKEN = "SIZNING_BOT_TOKENINGIZ"

bot = Bot(token=TOKEN)
dp = Dispatcher()

## /start buyrug'i uchun handler
@dp.message(Command("start"))
async def start_handler(message: types.Message):
    await message.answer(
        f"Salom, {message.from_user.full_name}! 👋\n"
        "Men ALGOR platformasi yordamida yaratilgan botman."
    )

## Har qanday oddiy matnli xabarni qaytarish (Echo)
@dp.message()
async def echo_handler(message: types.Message):
    await message.answer(f"Siz yozdingiz: {message.text}")

async def main():
    print("Bot ishga tushdi...")
    await dp.start_polling(bot)

if __name__ == "__main__":
    asyncio.run(main())

Run the program in the terminal:

python main.py

Now send /start to your bot in Telegram — it will reply right away!


4. Next step: growing the bot

Once the basic bot works, you can add features like these:

  • Keyboards: so the user can pick a menu item with one tap instead of typing.
  • A database (SQLite / PostgreSQL): to store the number of users, their scores or orders.
  • Working with groups: for example, the ALGOR helper bot (@algoruz_bot) automatically tracks students' solved problems in Telegram groups and posts a report every day at 21:00.

Using the right algorithms and data structures makes a bot several times faster. So don't forget to sharpen your skills on the ALGOR problems!

Was it useful? Share it with friends:
Telegram

Related articles

All articles →