LIVE PORTAL • Telegram v11.8 API Synchronized • Free Animated Stickers
translate Translated
#75 Bots

How do I create a bot?

Register the bot with @BotFather, then write the code that answers its messages. Registration takes about a minute. The code is the part that requires some programming, and there is no way round that: a bot is a program, so somebody has to write one.

Registering it

  1. Open a chat with @BotFather and press Start.
  2. Send /newbot.
  3. Give it a display name, then a username ending in bot.
  4. BotFather replies with a token. Treat it like a password, because anyone holding it controls the bot.

Then the code

The Bot API is plain HTTPS, so any language that can make a web request can drive a bot. Two ways to receive messages:

  • Long polling. Your program asks for new messages in a loop. Nothing to configure, works from a laptop, ideal while learning.
  • Webhooks. Telegram posts each update to a URL you own. Needs a public HTTPS endpoint, and is what you want in production.

Mature libraries exist for Python, JavaScript, Go, PHP and most other languages, and they remove nearly all of the boilerplate. The Introduction for Developers on core.telegram.org is the official starting point.

If you do not write code

There is no official no-code builder. Two realistic options: use one of the many bots other people have already published, or use a third-party bot-building service, keeping in mind that you are then trusting that service with your token and your users' messages.

Never paste your token into a public repository, a screenshot or a chat. If it leaks, send /revoke to BotFather immediately and issue a new one.
chevron_left All 98 official Telegram questions
Advertisement • Bottom Matched Content Slot