Cheat sheet

Telegram Bot API cheat sheet

Every call is https://api.telegram.org/bot<TOKEN>/<method> with JSON or form parameters. Responses are {"ok": true, "result": ...} or {"ok": false, "error_code": ..., "description": ...}.

Receiving updates

  • getUpdates long polling; pass offset = last update_id + 1
  • setWebhook url, secret_token, allowed_updates, drop_pending_updates
  • getWebhookInfo last_error_message, pending_update_count
  • deleteWebhook required before using getUpdates again
  • Header X-Telegram-Bot-Api-Secret-Token carries your secret_token
curl -s "https://api.telegram.org/bot$TOKEN/setWebhook" \
  -d url=https://example.com/tg \
  -d secret_token=$SECRET

Sending

  • sendMessage chat_id, text, parse_mode, reply_markup, link_preview_options
  • sendPhoto / sendDocument / sendMediaGroup
  • editMessageText, deleteMessage
  • sendChatAction typing indicator for slow replies
  • answerCallbackQuery always answer button presses
  • setMyCommands the command menu; scope and language_code

Update types

  • message, edited_message
  • callback_query inline button pressed
  • inline_query @yourbot query in any chat
  • my_chat_member bot added, removed or blocked
  • chat_member needs explicit allowed_updates
  • pre_checkout_query payments; answer within 10 seconds

Formatting

  • HTML: <b>, <i>, <u>, <s>, <code>, <pre>, <a href>, <tg-spoiler>, <blockquote>; escape &, < and >
  • MarkdownV2: *bold* _italic_ __underline__ ~strike~ ||spoiler|| `code`
  • In MarkdownV2 escape these with a backslash: _ * [ ] ( ) ~ ` > # + - = | { } . !

Convert between formats with the Markdown converter tool. Open

  • inline_keyboard: url, callback_data (1-64 bytes), web_app, switch_inline_query
  • keyboard + resize_keyboard, one_time_keyboard, is_persistent
  • remove_keyboard, force_reply
  • t.me/<bot>?start=<param> arrives as "/start param"
  • t.me/<bot>?startgroup=<param> add to a group

Keyboard builder ยท Deep link builder

Common errors

  • 400 Bad Request: can't parse entities unescaped MarkdownV2 or broken HTML
  • 400 message is too long over 4096 characters
  • 403 bot was blocked by the user stop messaging this chat
  • 409 Conflict two getUpdates consumers, or a webhook is set
  • 429 Too Many Requests wait parameters.retry_after seconds

Source: core.telegram.org/bots/api.

Last checked against official documentation: