Skip to content
TGWAY
Channels & Bots STEP 61 / 99

Telegram's Four APIs: Bot API, TDLib, Telegram API, Gateway

Telegram's four developer APIs: which account each acts as, what you need to start, and the order to pick them in, from the Bot API to TDLib, MTProto, Gateway.

  • Applies toDevelopers
  • LevelL4
  • Reading time4 min
  • Verified

The short answer

  1. 1If a bot can do it, use the Bot API; most projects stop there.
  2. 2Building your own Telegram app with a user account means TDLib; raw MTProto is a last resort.
  3. 3Delivering login codes through Telegram instead of SMS is the separate, paid Gateway API.
In this article
  1. Four ways in, sorted by which account acts
  2. Choosing, in order
  3. Bot accounts and user accounts are different on purpose
  4. FAQ
  5. At a glance

Four ways in, sorted by which account acts

Telegram offers developers four routes, and the names are easy to mix up. The quickest way to tell them apart is to ask which kind of account your code acts as.

APIActs as · what you needUse it for
Bot APIA bot account · a token from @BotFatherNotifications, customer replies, group tools, mini apps
TDLibA user account · api_id, api_hash and a phone number loginBuilding your own Telegram app (a client)
Telegram APIUser or bot accounts · api_id and api_hashWorking with MTProto directly, when there is a clear reason TDLib won't do
Gateway APINo chat account · a Gateway account with prepaid fundsSending sign-up and login verification codes through Telegram instead of SMS
  • Bot API is a plain HTTPS interface. Telegram's servers handle the encryption and the connection to Telegram for you.
  • TDLib is Telegram's own client library. It takes care of networking, encryption and local storage, and can be used from any language that can call C functions; Java and .NET bindings are included.
  • The Telegram API is the same API the official apps use. You work with hundreds of methods on top of the MTProto protocol yourself.
  • The Gateway API is not a messaging tool at all. It is a paid service that delivers verification codes for your own product to your users' Telegram accounts.

Choosing, in order

  1. Can a bot do it? Replying after a person writes first, sending notifications, showing buttons and opening mini apps are all Bot API work. Most projects stop here; start with creating a bot with BotFather and your first Bot API requests.
  2. Do you need what a person sees? If your app shows a chat list, contacts and message history, use TDLib; see building TDLib.
  3. Is TDLib really unsuitable? Only then work with MTProto yourself, and accept that encryption, retries and message ordering are your responsibility; see MTProto at a glance.
  4. Do you only need to deliver login codes? That is the Gateway API; see the Telegram Gateway API.

Bot accounts and user accounts are different on purpose

Bot account (Bot API)User account (TDLib, Telegram API)
Start a conversationNo; a person must start the bot firstYes
Phone numberNot neededNeeded to log in
Group messagesBy default only commands and replies to the bot (privacy mode)Every message in groups it has joined
Created at@BotFathermy.telegram.org, API development tools

A bot that cannot message people first is not an inconvenience to work around. It is the anti-spam design. That is why doing bot work with an automated user account gets accounts into trouble; see bot accounts vs user-account automation.

FAQ

What is the difference between the Bot API and the Telegram API?

The Bot API is an HTTPS interface for bot accounts. The Telegram API is the MTProto API the official apps use, for user or bot accounts, and needs api_id and api_hash.

When should I use TDLib?

When you are building your own Telegram client for a user account. TDLib handles networking, encryption and storage for you.

What is the Telegram Gateway API for?

Sending sign-up and login verification codes for your own service to users through Telegram instead of SMS. It is a paid service.

Sources

Summary

At a glance

Telegram's Four APIs: Bot API, TDLib, Telegram API, Gateway — at a glance illustration
  1. 1Bot API

    Bot account, HTTPS, token from @BotFather.

  2. 2TDLib / API

    User account, api_id and api_hash, phone login.

  3. 3Gateway

    Paid verification codes, no chat account.

Share this guide

Send it to a friend who has the same question.

Telegram WhatsApp
More

Open on your phonePoint your phone camera here to open this guide.

Updated

Related articles

View all ›