A Telegram bot tutorial ends exactly where real work begins. The bot says “Hello!”, everyone applauds, the code goes to a server — and then it turns out production has its own life: messages arrive twice, a broadcast stalls at the thousandth send, and after a server restart users find themselves “in the middle of a conversation” nobody remembers.
Here is what to know before letting a bot near real people. It applies to business bot development and to your own side projects alike.
Webhook over polling — and protect it
There are two ways to receive updates: poll Telegram yourself (getUpdates, long polling) or give Telegram an address to push events to (a webhook). Polling suits development — no public address needed. For production a webhook is usually better: lower latency and no permanently hanging connection.
A webhook has a non-obvious catch: the address is public, so anyone can send a fake “update” on behalf of any user. When you set the webhook (setWebhook), pass the secret_token parameter: Telegram adds it to the X-Telegram-Bot-Api-Secret-Token header, and you drop requests without it. Without this, anyone who learns the URL can “press” buttons for your customers.
Second: answer Telegram quickly. If your server doesn’t return 2xx, Telegram assumes the event was lost and sends it again. Accept the update, put it on a queue, reply 200 at once and process it in the background.

Duplicate updates: make handling idempotent
The previous point implies something unpleasant: the same event can arrive more than once. If pressing “Pay” makes the bot create an order, a duplicate creates a second one. Every update has a unique, increasing update_id — remember the processed ones (at least the last few thousand) and skip repeats. For critical actions — orders, charges — also use your own unique operation key in the database.
Limits: a broadcast to 10,000 people is not a “for” loop
Telegram limits sending speed. Rules of thumb from the documentation: roughly 30 messages per second across different chats, no more than one message per second to the same chat, and about 20 messages per minute to one group. Send faster and the API answers 429 with a retry_after field — how many seconds to wait.
Practical takeaway: a broadcast is a queue with a controlled rate, not a loop. 10,000 recipients at 25 messages per second is about seven minutes, and that’s fine. Handle 429, respect retry_after, and don’t turn a limit into a ban.
State belongs in a database, not in memory
In tutorials a dialogue (“enter your name”, “now your phone”) is stored in a variable. While the process lives it works. Restart the server and every user loses their place in the flow. User state (which step they’re on, what they’ve entered) should live in a database or Redis, keyed by user and chat. A restart then becomes routine instead of an incident.
Buttons: 64 bytes and a mandatory answer
An inline button has callback_data — a string returned to the bot on press. The limit is 1 to 64 bytes. Cyrillic takes two bytes per character and JSON eats the rest, so you can’t put big data in it: keep a short identifier (“buy:4815”) in callback_data and the details in your own database.
And the rule most often forgotten: every press must be answered with answerCallbackQuery, even without text. Otherwise the button shows an endless clock and the user decides the bot is broken.
Long operations. Generating a report or calling a slow service shouldn’t block the reply. Send “One second…” immediately, show the sendChatAction indicator (“typing…”) and deliver the result in a separate message.
Users who block the bot are normal
A person can stop the bot or delete the chat. The next send returns error 403 (“bot was blocked by the user”). If a broadcast can’t live with that, it will keep stubbornly knocking on those users, wasting limits and filling logs. Catch 403, mark the user inactive and don’t try to write again until they come back on their own. Also use the my_chat_member update to learn about blocks immediately.
One unescaped character and the bot goes silent
The MarkdownV2 mode requires escaping dozens of characters: dot, hyphen, brackets, exclamation mark. If a username like “Anna_Petrova (mom)” lands in a message unescaped, Telegram answers “can’t parse entities” and your bot sends nothing. The simplest cure is parse_mode: HTML, where only three characters need escaping: &, < and >. And always treat anything coming from a user as untrusted and escape it before insertion.
Two useful things people forget
- Deep links. A link like
t.me/your_bot?start=promo_springpasses a parameter to the bot. It tells you where a user came from — an ad, a QR code on packaging, a partner mailing — so you can measure conversion by source. - The command menu. The
setMyCommandsmethod shows a list of commands next to the input field. A bot without one looks lifeless, and users don’t know what it can do.

If the bot has a Mini App
Telegram Mini Apps pass user data to the app in an initData string. The main security rule: never trust a user ID sent by the client — verify the initData signature on the server using the bot token. Otherwise anyone who can open a console can substitute someone else’s ID.
The token, a test bot and personal data
A bot token is its password. Whoever has it can write on the bot’s behalf and read all updates. Three hygiene rules: the token lives in environment variables, not in the repository; neither the token nor full update bodies end up in logs; and at the slightest suspicion of a leak the token is revoked in BotFather with /revoke and replaced — it takes a minute.
Separately, create a second, test bot for development and checks. Experimenting on the live bot with real users is a sure way to send a test broadcast to every customer one day. A test bot with its own token and its own database is insurance that costs a few minutes of setup.
Finally, think about which data you collect. A bot easily gets the name, username and ID, and on request the phone number and location. This is personal data and the law applies to it: for example, rules on personal data and consent to processing. Collect only what the work needs, explain to the user why, store it carefully and give a way to delete it. If the project targets several countries, check local rules (GDPR in the EU, the personal data law in Russia) before launch, not after the first question from a customer.
The bottom line
A good bot differs from a tutorial bot not by clever features but by surviving the real world: duplicates, limits, blocks, restarts and hostile characters. If you need bot development for orders, booking, support or mailings, get in touch — we’ll design it so it doesn’t fall over at the first thousand users.



