Lesson 1 of 9 · 24m
Bot API vs MTProto: Picking the Right Transport
Understand what Bot API accounts can and cannot do, when MTProto is required, and why mixing the models casually creates maintenance debt.
The first architectural mistake I see with Telegram bots is not bad Python. It is choosing the wrong API because a blog post said 'Telegram bot' as if there were only one platform surface. There are two different worlds here: the Bot API, which Telegram operates as an HTTP gateway for bot accounts, and MTProto, the client protocol used by real Telegram clients. Pick based on the identity and capabilities you need, not on which library appeared first in search results.
Bot API is an application backend API
The Bot API is deliberately narrow and operationally friendly. You receive a bot token from @BotFather, call HTTPS methods on api.telegram.org, and process updates that Telegram delivers to you:
curl -sS "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/getMe" | jqThat simplicity matters. Telegram handles client protocol complexity, encryption sessions, synchronization, media upload mechanics, and much of the scaling edge. Your service only needs to keep the token secret, ingest updates, call methods, and obey platform limits.
MTProto is for user-client behavior
MTProto libraries such as Telethon or Pyrogram act as Telegram clients. They can authenticate as a user, read messages visible to that user, join conversations, and access functionality that bots do not have. That power comes with hard responsibilities: session files are credentials, user accounts have anti-abuse restrictions, and automating a human account can violate Telegram rules or user expectations.
# Telethon sketch: this is a user client, not a Bot API bot.
async with TelegramClient("operations.session", api_id, api_hash) as client:
async for message in client.iter_messages("some_channel", limit=20):
print(message.id, message.text)If the product requirement begins with 'as a user, read everything in this group' or 'automate my personal account,' you are in MTProto territory. If it begins with 'customers interact with our service bot,' you probably are not.
Capability comparison that matters
Need Bot API MTProto user client
Commands, keyboards, payments yes generally wrong tool
Webhook delivery by Telegram yes no, client event model
Read arbitrary user-visible history no yes
Act as a normal user no yes
Bot identity and bot privacy mode yes no
Operate without user-account risk yes noBot accounts also have platform constraints: they cannot initiate arbitrary direct messages to users who have not started them, cannot read every group message unless privacy mode permits it, and cannot perform many administration or social graph operations available to user clients.
The hybrid trap
A production system can use both, but separate them. Do not let one worker casually own a bot token and a user session with shared mutable state. The trust boundaries, rate limits, terms, failure modes, and incident response differ. Put each integration behind its own adapter, and make the application domain logic independent of Telegram transport details.
Decision rule for a new hire
Default to Bot API. Move to MTProto only when you can name a capability the Bot API does not provide and you are prepared to protect user-session credentials like production signing keys. If the answer is 'MTProto because it is more powerful,' stop. Power is not the requirement.
Field notes
@BotFathertokens are bearer credentials. Rotate them after leakage and treat logs containing them as sensitive.- Bot API file download URLs also contain the bot token; do not paste them into tickets or public logs.
- MTProto session files are portable credentials. File permissions and backup policy matter.
- A bot cannot force-start a DM with a user. Design onboarding links and deep links instead.
- Bot privacy mode changes what group messages arrive. Test in a real group, not only in DM.
Was this lesson helpful?