How to Choose the Right Library for a Telegram Bot
Your choice will depend on whether you decide to use Bot API or Telegram API. I've covered the differences on the previous page; 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.
There are Bot API libraries 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 is not primarily focused on developing bots, I started the Folds framework, which is built on top of Telethon and is designed to create simple and scalable bot programs.
As of alternatives, there are Pyrogram for Python and mtcute or GramJS for JavaScript.
Getting started
Here is a simple example of a bot that repeats after the user 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.