/telegram-skills:tg-bot-opsfrom telegram-skills
Guides production Telegram bot operations: webhook vs long polling, allowed_updates, secret token, bot settings, rate limits (429), broadcast limits, lost updates, and local Bot API server fallback.
Ships in telegram-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Checked against the official docs on 2026-12-02: Bot API 10.5 (November 22, 2026). Reports from trackers are labeled with their date. No scenario here was run against a live bot; scripts/retry_policy.py has unit tests on simulated responses.
Mutually exclusive. Either way, Telegram keeps undelivered updates at most 24 hours.
| Long polling | Webhook | |
|---|---|---|
| Fits | one process, no public HTTPS, a local machine | several workers, serverless |
| Ack | next getUpdates with a higher offset | your 2xx response |
| Limits | limit 1-100, timeout above 0 | ports 443, 80, 88, 8443; max_connections 1-100, default 40 |
| Failure | the same updates return until offset moves | non-2xx is repeated, then Telegram gives up "after a reasonable amount of attempts" |
Switching: getUpdates doesn't work while a webhook is set; use deleteWebhook. Keep drop_pending_updates off on a selling bot: it discards unprocessed successful_payment messages too.
Monitor getWebhookInfo: pending_update_count, last_error_message, last_error_date, allowed_updates.
A reply in the webhook response body (method plus parameters) saves a request, but its success and result can't be known. Use a normal request for anything you must confirm.
Webhook setup:
setWebhook with secret_token: 1-256 characters of A-Za-z0-9_-.X-Telegram-Bot-Api-Secret-Token header differs, using a constant-time compare.pre_checkout_query right in the handler, ahead of any queue: it expires in 10 seconds (tg-stars-payments).chat_member, message_reaction and message_reaction_count, which need explicit opt-in and admin rights.Send the full list on startup and compare it with getWebhookInfo.allowed_updates. Types added in 2026: guest_message, managed_bot, subscription, stopped_message_generation, and in Bot API 10.4 widget_query, shared_widget_query (tg-widgets).
Bot API 10.5 lets the bot change its own settings with setMySettings; before it, only @BotFather did. Parameters left out stay as they are. getMe now returns BotFullInfo, which reads most of them back; the table says which.
| Setting | setMySettings parameter | Read in BotFullInfo |
|---|---|---|
| Inline mode | supports_inline_queries, inline_query_placeholder (empty string for the default), needs_inline_query_location | the same names |
| Share of chosen inline results | inline_feedback_share_denominator: 1, 10, 100 or 1000; 0 stops them | not returned |
| Added to groups | can_join_groups | can_join_groups |
| Privacy mode | can_read_all_group_messages: true turns it off | can_read_all_group_messages |
| Topics in private chats | has_topics_enabled, allows_users_to_create_topics, has_topic_sidebar (topic list in a sidebar) | the same names |
| Business, managed bots, guest and join request queries, talking to other bots | can_connect_to_business, can_manage_bots, supports_guest_queries, supports_join_request_queries, can_communicate_with_bots | all but can_communicate_with_bots |
| Callback queries | callback_query_mode | not returned |
callback_query_mode decides how a callback from a button in the bot's own message arrives:
default: always in message; an inaccessible message comes as InaccessibleMessage.auto: inline_message_id replaces message when the message is inaccessible to the bot; a message deleted a moment ago can still arrive as an inaccessible message.inline: always inline_message_id.With auto or inline, every callback handler reads both fields and edits by inline_message_id when message is absent.
Other 10.5 changes to the bot itself:
BotFullInfo adds active_usernames, inline_query_placeholder, needs_inline_query_location, has_topic_sidebar. The fields that only getMe used to fill (can_join_groups, supports_inline_queries, has_main_web_app, has_topics_enabled and the rest) are gone from User: read them from getMe, never from a User in an update. A typed library still on 10.4 may parse getMe into the old User model; update it.https://t.me/botinvite/<bot_username>. The bot may write to them first. It learns about each one from a write_access_allowed service message whose WriteAccessAllowed has inviter, the owner.Settings are global to the bot: change them in one place at startup or by an admin command, log the call and its True result, and confirm the readable ones with getMe. callback_query_mode, inline_feedback_share_denominator and can_communicate_with_bots can't be read back: keep the value you set in your own config.
On by default. In groups the bot sees commands meant for it, replies to it and messages sent via it, plus all service messages. An admin bot sees everything. Turn it off with setMySettings (can_read_all_group_messages: true) or in @BotFather. After the @BotFather route, re-add the bot to each group for the change to take effect; whether setMySettings needs the same re-add isn't documented, so check in a test group before relying on it.
Documented limits: about 1 message per second per chat (short bursts allowed), 20 per minute in a group, about 30 per second for bulk. Treat the numbers as approximate and let retry_after rule. Flood limits are not raised in the test environment and may at times be stricter, and a maintainer says the local server doesn't change them (2024-12-13). answerCallbackQuery has no limit, editing is under the per-chat limit (maintainer, 2024-10-09).
| Response | Meaning | Action |
|---|---|---|
429 with parameters.retry_after | not applied | hold the whole scope that long, then repeat |
parameters.migrate_to_chat_id | group became a supergroup | store the new id, repeat |
| other 4xx | rejected | fix the request; 403 usually means the user blocked the bot |
| 5xx, timeout, dropped connection, non-JSON | unknown, it may have been delivered | report it and reconcile; resend only if a duplicate is harmless |
import retry_policy as rp
gate = rp.FloodGate() # one per process
def make_request(): # called on every attempt
return build_multipart(url, fields, open(path, 'rb'))
decision = rp.send(make_request, transport, gate, f'chat:{chat_id}')
if decision.action == rp.UNKNOWN:
park_for_reconcile(decision.reason) # never treat this as a failed send
transport(request) is yours: it returns (status, body), it should close the file, and any exception it raises counts as unknown, because the bytes may have left. make_request runs outside that guard: when it raises, for example on a missing file, nothing was sent and the exception reaches you.
FloodGate lives in the memory of one process. Several workers need a shared store for pauses, for example Redis with a key per scope and a TTL of retry_after.
The pause length belongs to the server: Decision.wait carries retry_after as received. send sleeps up to max_inline_wait (60 seconds by default). A longer pause comes back as FAIL with the real wait, so a handler can reschedule the send and free its worker.
Two failure modes this shape avoids, both reported in libraries in 2026:
RetryAfter pause (PTB #5338, closed 2026-09-13). FloodGate ends a pause by clock only. aiogram has no built-in rate limiter yet (#1875, open on 2026-10-30).Scope the gate by chat for sends, and by bot for a broadcast. For bulk, a queue at 30 per second or fewer is cheaper than handling 429s.
allow_paid_broadcast: true raises the limit to 1000 messages per second, at 0.1 Star per message above the free 30. Eligibility is stated two ways, and @BotFather decides:
| Source | Requirement | Checked |
|---|---|---|
| Bot API page | 10,000 Stars on the balance | 2026-10-30 |
| Bot FAQ, Terms § 6.2.5 | 100,000 Stars and 100,000 monthly active users | 2026-10-30 |
getUpdates is called with a higher offset. Recalculate offset after every response and save the update first, so a crash replays it.update_id for transport repeats and by the domain key for money (tg-stars-payments). After a week without updates the next update_id is random, so never assume it only grows across a gap.New Bot API versions add fields and types without notice to old clients. A library that fails to decode one update never moves offset, and the bot stops. Bot API 10.3 did exactly that: RichTextButton made aiogram raise ClientDecodeError and block polling until 3.31 (#1890, 2026-08-25). Deeply nested rich_message.blocks stalled validation with a single update (#1842, 2026-06-29). Bot API 10.5 has two changes of the same kind: expandable_blockquote carries blocks instead of text, and getMe returns BotFullInfo instead of User.
Before each Bot API version reaches users:
offset (or return 2xx).update_id and a growing pending_update_count.for update in updates:
store_raw(update) # before anything can fail
try:
handle(decode(update))
except Exception as error:
dead_letter(update, error) # poison stops here, offset still moves
offset = update['update_id'] + 1
A successful_payment in the dead-letter store still owes the buyer: replay it through the ledger, or follow the recovery rules in tg-stars-payments, because getStarTransactions lacks subscription_expiration_date.
On 2026-07-13 at 19:24 UTC the t.me domain went down for about a day after an OFAC listing named a t.me address; telegram.me kept working (TechCrunch, Cybernews). No official post-mortem was found.
The fallback isn't universal. Reports from that day:
telegram.me worked; profile images saved on t.me broke, and the swap fixed them (HN).createInvoiceLink returned telegram.me, and the invoice did not open until the host was replaced with t.me (PTB #5296).openTelegramLink rejected telegram.me and telegram.dog (#879, closed 2026-07-14).So keep the host in one config value, avoid t.me allowlists in validators and store usernames instead of full links. A URL returned by the API can fail too: open an invoice on a client to check it, and test any fallback for invoices and Mini App links before relying on it.
Run tdlib/telegram-bot-api for these features: unlimited download, upload up to 2000 MB, file:// paths, absolute file_path from getFile, HTTP webhooks on any port and local IP, max_webhook_connections up to 100000. Everything else, including flood limits, stays.
Moving a bot:
logOut before pointing it at the local server. The bot can't return to the cloud for 10 minutes.deleteWebhook, then close. close returns 429 during the first 10 minutes after launch.Done when getMe answers on the new URL and updates arrive there.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
telegram-bot, bot-ops, production-deployment, webhook, rate-limiting
15 skills in this plugin
/tg-capability-mapUse before promising a Telegram feature or designing around one: what a bot can do in Bot API, what lives only in the client or MTProto (scheduled posts, channel stats, poll stats, channel stories, folders, boosts, welcome messages, communities), and what never to promise from a bot./tg-classic-messagesUse when sending or editing ordinary Telegram bot messages: sendMessage text, MarkdownV2/HTML escaping and entities, quotes, date_time, custom emoji, link previews, photos and documents with captions, albums, upload size limits, protect_content, copy, forward, delete. Also use to choose between a classic message and a rich message./tg-markdown-to-richUse when converting an existing Markdown file or stdin into a Telegram Rich Message (InputRichMessage.markdown) for sendRichMessage, including file_id, URL, and multipart upload media bindings. Triggers: "send markdown to Telegram", "convert doc to rich message", "telegram rich message from file"./tg-miniapp-launch-authUse when choosing how a Telegram Mini App opens (keyboard, inline or menu button, main app, direct link, startapp, join request) or when a server must trust a Mini App user: validating initData by HMAC or Ed25519, signature in the check string, auth_date, isVersionAtLeast gating, origin protection, test launch links in the test environment./tg-miniapp-uiUse when building or debugging the interface of a Telegram Mini App: theme colors and dark mode, safe areas and notches, fullscreen, keyboard and viewport height, MainButton and SecondaryButton, BackButton, haptic feedback, performance on weak Android, or a layout bug that shows up only on a real iPhone, Android or Desktop client./tg-operator-cardsUse when turning the facts of one bot event — a payment, an order, an enrollment, a moderation decision — into a card for the person who runs the bot, in an admin chat or a private chat with the owner: a review card awaiting a decision or a receipt, read in two seconds on a phone.npx claudepluginhub serejaris/telegram-skills --plugin telegram-skillsOther plugins' skills for the same job