Skip to main content

Callback query

A callback query is the update that Telegram sends to a bot when a user presses a callback button on an inline keyboard. The update carries the data string that the bot set on the button, and the bot must answer it. A callback button, unlike a URL button, does not open a link: it asks the bot to act.

What a callback query contains

The Bot API object named CallbackQuery has a unique id, the user who pressed the button, and a data field with the string that the bot attached to that button. When the button sits on a message that the bot sent, the update also carries that message. The data field is the only way the bot learns which button was pressed, so the bot must choose each data string with care.

The 64-byte limit on button data

The callback_data of an inline button must be between 1 and 64 bytes. The limit is in bytes, not characters, so a Cyrillic letter takes two bytes in UTF-8 and a short Ukrainian or Russian label can use the budget quickly. Do not put a full record in the data string. Store the record on the server, and put a short key in the button, for example an action name and a numeric id.

Why the bot must answer

After a user presses a callback button, the Telegram client shows a progress bar until the bot calls the answerCallbackQuery method. The Bot API documentation states that the bot must call it even when no message is needed for the user. The method takes an optional text of 0 to 200 characters, a show_alert flag that shows an alert instead of a small notice at the top of the chat, and a cache_time that defaults to 0 seconds.

Callback buttons and channels

A callback query goes to a bot, so a button of this type needs a running bot that handles the update and keeps its own state. A button that only opens a page does not need this: use a URL button, which sends no update to the bot. Check the type of each button before you attach it to a scheduled post, and keep the bot token private, because anyone who holds the token can read the updates of the bot.

Related features

Put these concepts to work

Automate your Telegram publishing with AI content, quality scoring, and smart scheduling.