How to Choose the Right Library for a Telegram Bot
Your choice depends on whether you use Bot API or Telegram API. I've covered the differences on the previous page, so make sure to read it first.
Bot API libraries
A common choice for developing Telegram bots is a Python library called aiogram.Rocketgram is a popular alternative.
JavaScript is often used as well: check out Telegraf or GrammY.
Bot API libraries exist for many other languages, too. The official site has a list and seems to keep it up-to-date.
Telegram API libraries
For Python, the most popular library built with Telegram API is Telethon. Since Telethon isn't primarily focused on bot development, I created the Folds framework, which builds on top of Telethon and helps you create simple and scalable bots.
For JavaScript, the options include mtcute or GramJS.
Getting started
Here's a simple bot that echoes the user's messages in DM:
import asyncio
from aiogram import Bot, Dispatcher, F
from aiogram.types import Message
bot = Bot(token='YOUR_BOT_TOKEN_HERE')
dp = Dispatcher()
@dp.message(F.chat.type == ChatType.PRIVATE)
async def echo(message: Message):
await message.answer(message.text)
if __name__ == '__main__':
asyncio.run(dp.start_polling(bot))But first, you will need to register a bot and obtain the token.
