Docs

Buttons

Buttons in a bot's messages, presses, and answers as a toast, a dialog or a link.

Buttons are part of a bot's message, not a separate keyboard: they sit under the text, and editing the message replaces them with it. Only bots can write buttons.

Adding buttons

buttons is an array of rows, a row is an array of buttons. Each button has text and exactly one action:

{
  "chat_id": "…",
  "text": "Deploy build 42?",
  "buttons": [
    [ { "text": "Yes", "callback_data": "deploy:42" }, { "text": "No", "callback_data": "cancel:42" } ],
    [ { "text": "Log", "url": "https://ci.example.org/42" }, { "text": "Copy hash", "copy_text": "9f2c1e7" } ]
  ]
}
ActionWhat a press does
callback_dataUp to 64 bytes. The bot gets a callback_query and answers.
urlThe app opens the address like an ordinary link, with confirmation.
copy_textUp to 256 characters. The app copies the text and says "Copied".

Up to 8 rows, up to 8 buttons per row, up to 32 buttons per message; a label is up to 64 characters.

Buttons are not forwarded with the message. A personal bot answering on someone's behalf cannot write buttons. Older app versions see the line 🔘 Yes · No instead of the buttons.

A press

A press of a button with callback_data arrives as an update:

{
  "update_id": 15,
  "callback_query": {
    "id": "…",
    "from": { "id": "…", "is_bot": false, "first_name": "Anna" },
    "chat": { "id": "…", "type": "group", "title": "Releases" },
    "message": { "message_id": "…", "text": "Deploy build 42?", ... },
    "button_id": "…",
    "data": "deploy:42"
  }
}

While the bot thinks, the button shows progress.

Answering a press

Answer with answerCallbackQuery within 10 seconds. The bot decides what the person sees:

AnswerWhat the person sees
{"callback_query_id": "…", "text": "Done"}The app's toast: at the bottom above the composer on a phone, at the top right on a computer. A new one replaces the previous, so quick presses do not pile up.
{"callback_query_id": "…", "text": "Not allowed", "show_alert": true}A dialog the person closes.
{"callback_query_id": "…", "url": "https://…"}The address opens.
{"callback_query_id": "…"}Nothing.

If the bot does not answer within 10 seconds, the press ends with an empty answer and shows nothing. The answer's text is up to 200 characters.

Often the bot changes the message itself along with the answer, for example removing the buttons after a choice:

{ "chat_id": "…", "message_id": "…", "text": "Build 42 deployed ✅" }

(editMessage without buttons removes the buttons.)

Instead of a toast, the bot can answer with an ephemeral message only the presser sees.

On this page