telegram-crawler/data/web/blogfork.telegram.org/api/bots/buttons.html
2024-02-15 06:31:44 +00:00

259 lines
31 KiB
HTML

<!DOCTYPE html>
<html class="">
<head>
<meta charset="utf-8">
<title>Buttons</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="description" content="Users can interact with your bot via buttons or even inline buttons, straight from inline messages in any chat. ">
<meta property="og:title" content="Buttons">
<meta property="og:image" content="">
<meta property="og:description" content="Users can interact with your bot via buttons or even inline buttons, straight from inline messages in any chat. ">
<link rel="icon" type="image/svg+xml" href="/img/website_icon.svg?4">
<link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
<link rel="alternate icon" href="/img/favicon.ico" type="image/x-icon" />
<link href="/css/bootstrap.min.css?3" rel="stylesheet">
<link href="/css/telegram.css?236" rel="stylesheet" media="screen">
<style>
</style>
</head>
<body class="preload">
<div class="dev_page_wrap">
<div class="dev_page_head navbar navbar-static-top navbar-tg">
<div class="navbar-inner">
<div class="container clearfix">
<ul class="nav navbar-nav navbar-right hidden-xs"><li class="navbar-twitter"><a href="https://twitter.com/telegram" target="_blank" data-track="Follow/Twitter" onclick="trackDlClick(this, event)"><i class="icon icon-twitter"></i><span> Twitter</span></a></li></ul>
<ul class="nav navbar-nav">
<li><a href="//telegram.org/">Home</a></li>
<li class="hidden-xs"><a href="//telegram.org/faq">FAQ</a></li>
<li class="hidden-xs"><a href="//telegram.org/apps">Apps</a></li>
<li class="active"><a href="/api">API</a></li>
<li class=""><a href="/mtproto">Protocol</a></li>
<li class=""><a href="/schema">Schema</a></li>
</ul>
</div>
</div>
</div>
<div class="container clearfix">
<div class="dev_page">
<div id="dev_page_content_wrap" class=" ">
<div class="dev_page_bread_crumbs"><ul class="breadcrumb clearfix"><li><a href="/api" >API</a></li><i class="icon icon-breadcrumb-divider"></i><li><a href="/api/bots%2Fbuttons" >Buttons</a></li></ul></div>
<h1 id="dev_page_title">Buttons</h1>
<div id="dev_page_content"><!-- scroll_nav -->
<p>Users can interact with your bot via <strong>buttons</strong> or even <strong>inline buttons</strong>, straight from inline <strong>messages</strong> in <strong>any</strong> chat.<br>
This article describes the full button flow, using the MTProto API. </p>
<p>For a simplified description using the HTTP bot API, see <a href="/bots/features#keyboards">here »</a>. </p>
<h3><a class="anchor" href="#buttons" id="buttons" name="buttons"><i class="anchor-icon"></i></a>Buttons</h3>
<pre><code><a href='/constructor/keyboardButton'>keyboardButton</a>#a2fa4880 text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonUrl'>keyboardButtonUrl</a>#258aff05 text:<a href='/type/string'>string</a> url:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonCallback'>keyboardButtonCallback</a>#35bbdb6b flags:<a href='/type/%23'>#</a> requires_password:flags.0?<a href='/constructor/true'>true</a> text:<a href='/type/string'>string</a> data:<a href='/type/bytes'>bytes</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRequestPhone'>keyboardButtonRequestPhone</a>#b16a6c29 text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRequestGeoLocation'>keyboardButtonRequestGeoLocation</a>#fc796b3f text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonSwitchInline'>keyboardButtonSwitchInline</a>#93b9fbb5 flags:<a href='/type/%23'>#</a> same_peer:flags.0?<a href='/constructor/true'>true</a> text:<a href='/type/string'>string</a> query:<a href='/type/string'>string</a> peer_types:flags.1?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/InlineQueryPeerType'>InlineQueryPeerType</a>&gt; = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonGame'>keyboardButtonGame</a>#50f41ccf text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonBuy'>keyboardButtonBuy</a>#afd93fbb text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonUrlAuth'>keyboardButtonUrlAuth</a>#10b78d29 flags:<a href='/type/%23'>#</a> text:<a href='/type/string'>string</a> fwd_text:flags.0?<a href='/type/string'>string</a> url:<a href='/type/string'>string</a> button_id:<a href='/type/int'>int</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/inputKeyboardButtonUrlAuth'>inputKeyboardButtonUrlAuth</a>#d02e7fd4 flags:<a href='/type/%23'>#</a> request_write_access:flags.0?<a href='/constructor/true'>true</a> text:<a href='/type/string'>string</a> fwd_text:flags.1?<a href='/type/string'>string</a> url:<a href='/type/string'>string</a> bot:<a href='/type/InputUser'>InputUser</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRequestPoll'>keyboardButtonRequestPoll</a>#bbc7515d flags:<a href='/type/%23'>#</a> quiz:flags.0?<a href='/type/Bool'>Bool</a> text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRequestPeer'>keyboardButtonRequestPeer</a>#53d7bfd8 text:<a href='/type/string'>string</a> button_id:<a href='/type/int'>int</a> peer_type:<a href='/type/RequestPeerType'>RequestPeerType</a> max_quantity:<a href='/type/int'>int</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRow'>keyboardButtonRow</a>#77608b83 buttons:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/KeyboardButton'>KeyboardButton</a>&gt; = <a href='/type/KeyboardButtonRow'>KeyboardButtonRow</a>;
<a href='/constructor/replyKeyboardHide'>replyKeyboardHide</a>#a03e5b85 flags:<a href='/type/%23'>#</a> selective:flags.2?<a href='/constructor/true'>true</a> = <a href='/type/ReplyMarkup'>ReplyMarkup</a>;
<a href='/constructor/replyKeyboardForceReply'>replyKeyboardForceReply</a>#86b40b08 flags:<a href='/type/%23'>#</a> single_use:flags.1?<a href='/constructor/true'>true</a> selective:flags.2?<a href='/constructor/true'>true</a> placeholder:flags.3?<a href='/type/string'>string</a> = <a href='/type/ReplyMarkup'>ReplyMarkup</a>;
<a href='/constructor/replyKeyboardMarkup'>replyKeyboardMarkup</a>#85dd99d1 flags:<a href='/type/%23'>#</a> resize:flags.0?<a href='/constructor/true'>true</a> single_use:flags.1?<a href='/constructor/true'>true</a> selective:flags.2?<a href='/constructor/true'>true</a> persistent:flags.4?<a href='/constructor/true'>true</a> rows:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/KeyboardButtonRow'>KeyboardButtonRow</a>&gt; placeholder:flags.3?<a href='/type/string'>string</a> = <a href='/type/ReplyMarkup'>ReplyMarkup</a>;
<a href='/constructor/replyInlineMarkup'>replyInlineMarkup</a>#48a30254 rows:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/KeyboardButtonRow'>KeyboardButtonRow</a>&gt; = <a href='/type/ReplyMarkup'>ReplyMarkup</a>;
<a href='/constructor/message'>message</a>#76bec211 flags:<a href='/type/%23'>#</a> out:flags.1?<a href='/constructor/true'>true</a> mentioned:flags.4?<a href='/constructor/true'>true</a> media_unread:flags.5?<a href='/constructor/true'>true</a> silent:flags.13?<a href='/constructor/true'>true</a> post:flags.14?<a href='/constructor/true'>true</a> from_scheduled:flags.18?<a href='/constructor/true'>true</a> legacy:flags.19?<a href='/constructor/true'>true</a> edit_hide:flags.21?<a href='/constructor/true'>true</a> pinned:flags.24?<a href='/constructor/true'>true</a> noforwards:flags.26?<a href='/constructor/true'>true</a> invert_media:flags.27?<a href='/constructor/true'>true</a> id:<a href='/type/int'>int</a> from_id:flags.8?<a href='/type/Peer'>Peer</a> peer_id:<a href='/type/Peer'>Peer</a> saved_peer_id:flags.28?<a href='/type/Peer'>Peer</a> fwd_from:flags.2?<a href='/type/MessageFwdHeader'>MessageFwdHeader</a> via_bot_id:flags.11?<a href='/type/long'>long</a> reply_to:flags.3?<a href='/type/MessageReplyHeader'>MessageReplyHeader</a> date:<a href='/type/int'>int</a> message:<a href='/type/string'>string</a> media:flags.9?<a href='/type/MessageMedia'>MessageMedia</a> reply_markup:flags.6?<a href='/type/ReplyMarkup'>ReplyMarkup</a> entities:flags.7?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/MessageEntity'>MessageEntity</a>&gt; views:flags.10?<a href='/type/int'>int</a> forwards:flags.10?<a href='/type/int'>int</a> replies:flags.23?<a href='/type/MessageReplies'>MessageReplies</a> edit_date:flags.15?<a href='/type/int'>int</a> post_author:flags.16?<a href='/type/string'>string</a> grouped_id:flags.17?<a href='/type/long'>long</a> reactions:flags.20?<a href='/type/MessageReactions'>MessageReactions</a> restriction_reason:flags.22?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/RestrictionReason'>RestrictionReason</a>&gt; ttl_period:flags.25?<a href='/type/int'>int</a> = <a href='/type/Message'>Message</a>;
---functions---
<a href='/method/messages.sendMessage'>messages.sendMessage</a>#280d096f flags:<a href='/type/%23'>#</a> no_webpage:flags.1?<a href='/constructor/true'>true</a> silent:flags.5?<a href='/constructor/true'>true</a> background:flags.6?<a href='/constructor/true'>true</a> clear_draft:flags.7?<a href='/constructor/true'>true</a> noforwards:flags.14?<a href='/constructor/true'>true</a> update_stickersets_order:flags.15?<a href='/constructor/true'>true</a> invert_media:flags.16?<a href='/constructor/true'>true</a> peer:<a href='/type/InputPeer'>InputPeer</a> reply_to:flags.0?<a href='/type/InputReplyTo'>InputReplyTo</a> message:<a href='/type/string'>string</a> random_id:<a href='/type/long'>long</a> reply_markup:flags.2?<a href='/type/ReplyMarkup'>ReplyMarkup</a> entities:flags.3?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/MessageEntity'>MessageEntity</a>&gt; schedule_date:flags.10?<a href='/type/int'>int</a> send_as:flags.13?<a href='/type/InputPeer'>InputPeer</a> = <a href='/type/Updates'>Updates</a>;</code></pre>
<p>Bots can attach a <a href="/type/ReplyMarkup">ReplyMarkup</a> constructor to outgoing messages, to attach an <a href="/bots/features#inline-keyboards">inline keyboard</a> or a <a href="/bots/features#keyboards">custom reply keyboard</a>:</p>
<ul>
<li><a href="/constructor/replyKeyboardMarkup">replyKeyboardMarkup</a> - Sends a <a href="/bots/features#keyboards">custom reply keyboard</a>. <br> User clients receiving such a constructor should display a <a href="/bots/features#keyboards">special keyboard</a> with custom reply options.</li>
<li><a href="/constructor/replyKeyboardHide">replyKeyboardHide</a> - Hides the <a href="/bots/features#keyboards">custom reply keyboard</a>. <br> User clients receiving this constructor should hide the <a href="/bots/features#keyboards">custom reply keyboard</a> opened by <a href="/constructor/replyKeyboardMarkup">replyKeyboardMarkup</a></li>
<li><a href="/constructor/replyKeyboardForceReply">replyKeyboardForceReply</a> - Sends a <a href="/bots/api#forcereply">force reply</a> constructor <br> User clients receiving a message with this constructor should act as if the user had clicked on the reply button of the message, displaying the reply UI. </li>
<li><a href="/constructor/replyInlineMarkup">replyInlineMarkup</a> - Attaches an <a href="/bots/features#inline-keyboards">inline keyboard</a> to the message, allowing users to send callback data to the bot without sending actual messages to the current chat.</li>
</ul>
<h3><a class="anchor" href="#pressing-buttons" id="pressing-buttons" name="pressing-buttons"><i class="anchor-icon"></i></a>Pressing buttons</h3>
<pre><code><a href='/constructor/requestPeerTypeUser'>requestPeerTypeUser</a>#5f3b8a00 flags:<a href='/type/%23'>#</a> bot:flags.0?<a href='/type/Bool'>Bool</a> premium:flags.1?<a href='/type/Bool'>Bool</a> = <a href='/type/RequestPeerType'>RequestPeerType</a>;
<a href='/constructor/requestPeerTypeChat'>requestPeerTypeChat</a>#c9f06e1b flags:<a href='/type/%23'>#</a> creator:flags.0?<a href='/constructor/true'>true</a> bot_participant:flags.5?<a href='/constructor/true'>true</a> has_username:flags.3?<a href='/type/Bool'>Bool</a> forum:flags.4?<a href='/type/Bool'>Bool</a> user_admin_rights:flags.1?<a href='/type/ChatAdminRights'>ChatAdminRights</a> bot_admin_rights:flags.2?<a href='/type/ChatAdminRights'>ChatAdminRights</a> = <a href='/type/RequestPeerType'>RequestPeerType</a>;
<a href='/constructor/requestPeerTypeBroadcast'>requestPeerTypeBroadcast</a>#339bef6c flags:<a href='/type/%23'>#</a> creator:flags.0?<a href='/constructor/true'>true</a> has_username:flags.3?<a href='/type/Bool'>Bool</a> user_admin_rights:flags.1?<a href='/type/ChatAdminRights'>ChatAdminRights</a> bot_admin_rights:flags.2?<a href='/type/ChatAdminRights'>ChatAdminRights</a> = <a href='/type/RequestPeerType'>RequestPeerType</a>;
<a href='/constructor/keyboardButtonRequestPeer'>keyboardButtonRequestPeer</a>#53d7bfd8 text:<a href='/type/string'>string</a> button_id:<a href='/type/int'>int</a> peer_type:<a href='/type/RequestPeerType'>RequestPeerType</a> max_quantity:<a href='/type/int'>int</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/messageActionRequestedPeer'>messageActionRequestedPeer</a>#31518e9b button_id:<a href='/type/int'>int</a> peers:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/Peer'>Peer</a>&gt; = <a href='/type/MessageAction'>MessageAction</a>;
<a href='/constructor/keyboardButton'>keyboardButton</a>#a2fa4880 text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonUrl'>keyboardButtonUrl</a>#258aff05 text:<a href='/type/string'>string</a> url:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonCallback'>keyboardButtonCallback</a>#35bbdb6b flags:<a href='/type/%23'>#</a> requires_password:flags.0?<a href='/constructor/true'>true</a> text:<a href='/type/string'>string</a> data:<a href='/type/bytes'>bytes</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRequestPhone'>keyboardButtonRequestPhone</a>#b16a6c29 text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRequestGeoLocation'>keyboardButtonRequestGeoLocation</a>#fc796b3f text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRequestPoll'>keyboardButtonRequestPoll</a>#bbc7515d flags:<a href='/type/%23'>#</a> quiz:flags.0?<a href='/type/Bool'>Bool</a> text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonSwitchInline'>keyboardButtonSwitchInline</a>#93b9fbb5 flags:<a href='/type/%23'>#</a> same_peer:flags.0?<a href='/constructor/true'>true</a> text:<a href='/type/string'>string</a> query:<a href='/type/string'>string</a> peer_types:flags.1?<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/InlineQueryPeerType'>InlineQueryPeerType</a>&gt; = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonGame'>keyboardButtonGame</a>#50f41ccf text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonBuy'>keyboardButtonBuy</a>#afd93fbb text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonUrlAuth'>keyboardButtonUrlAuth</a>#10b78d29 flags:<a href='/type/%23'>#</a> text:<a href='/type/string'>string</a> fwd_text:flags.0?<a href='/type/string'>string</a> url:<a href='/type/string'>string</a> button_id:<a href='/type/int'>int</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
// Used by bots to send a keyboardButtonUrlAuth
<a href='/constructor/inputKeyboardButtonUrlAuth'>inputKeyboardButtonUrlAuth</a>#d02e7fd4 flags:<a href='/type/%23'>#</a> request_write_access:flags.0?<a href='/constructor/true'>true</a> text:<a href='/type/string'>string</a> fwd_text:flags.1?<a href='/type/string'>string</a> url:<a href='/type/string'>string</a> bot:<a href='/type/InputUser'>InputUser</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonRow'>keyboardButtonRow</a>#77608b83 buttons:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/KeyboardButton'>KeyboardButton</a>&gt; = <a href='/type/KeyboardButtonRow'>KeyboardButtonRow</a>;
---functions---
<a href='/method/messages.sendBotRequestedPeer'>messages.sendBotRequestedPeer</a>#91b2d060 peer:<a href='/type/InputPeer'>InputPeer</a> msg_id:<a href='/type/int'>int</a> button_id:<a href='/type/int'>int</a> requested_peers:<a href='/type/Vector%20t'>Vector</a>&lt;<a href='/type/InputPeer'>InputPeer</a>&gt; = <a href='/type/Updates'>Updates</a>;</code></pre>
<p>Both <a href="/bots/features#keyboards">reply</a> and <a href="/bots/features#inline-keyboards">inline</a> keyboards are composed of a vector of <a href="/constructor/keyboardButtonRow">rows</a>, each row containing a vector of <a href="/type/KeyboardButton">buttons</a>, for each column.<br>
Each row can have a different number of columns, and user clients should properly handle clicking buttons of every type. </p>
<p>Buttons available only in reply keyboards:</p>
<ul>
<li><a href="/constructor/keyboardButton">keyboardButton</a> - Send a message to the chat, replying to the message that attached the <a href="/bots/features#keyboards">reply keyboard</a></li>
<li><a href="/constructor/keyboardButtonRequestPhone">keyboardButtonRequestPhone</a> - Only in private chats, send the current user's contact to the chat, replying to the message that attached the <a href="/bots/features#keyboards">reply keyboard</a></li>
<li><a href="/constructor/keyboardButtonRequestGeoLocation">keyboardButtonRequestGeoLocation</a> - Only in private chats, send the current user's geolocation to the chat, replying to the message that attached the <a href="/bots/features#keyboards">reply keyboard</a></li>
<li><a href="/constructor/keyboardButtonRequestPoll">keyboardButtonRequestPoll</a> - Only in private chats, prompts the user to create and send a <a href="/api/poll">poll</a> (or a quiz poll, depending on the <code>quiz</code> flag), replying to the message that attached the <a href="/bots/features#keyboards">reply keyboard</a></li>
<li><a href="/constructor/keyboardButtonRequestPeer">keyboardButtonRequestPeer</a> - Prompts the user to select and share a peer with the bot using <a href="/method/messages.sendBotRequestedPeer">messages.sendBotRequestedPeer</a>, according to the criteria specified in the <a href="/type/RequestPeerType">RequestPeerType</a> constructor. <a href="/constructor/keyboardButtonRequestPeer">keyboardButtonRequestPeer</a>.<code>button_id</code> must be passed to the method: the peer and the specified <code>button_id</code> will be received by the bot as a <a href="/constructor/messageActionRequestedPeer">messageActionRequestedPeer</a> service message. </li>
</ul>
<p>Buttons available only in inline keyboards:</p>
<ul>
<li><a href="/constructor/keyboardButtonUrl">keyboardButtonUrl</a> - Open the URL, showing a "Do you want to open this URL?" prompt (unless the URL is one of the <a href="https://github.com/DrKLO/Telegram/blob/002c01ecd37cd08ed07b3ed84d79318d091dfc85/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java#L351">internal URIs</a>, in which case the URL should be opened right away)</li>
<li><a href="/constructor/keyboardButtonCallback">keyboardButtonCallback</a> - Send the callback data to the bot, optionally providing the user's 2FA SRP payload for identity verification, see <a href="#callback-queries">here for more info »</a></li>
<li><a href="/constructor/keyboardButtonSwitchInline">keyboardButtonSwitchInline</a><ul>
<li>If <code>keyboardButtonSwitchInline.same_peer</code> is set, insert the bot's username and <code>keyboardButtonSwitchInline.query</code> in the current chat's input field, triggering an <a href="/api/bots/inline">inline query</a>.</li>
<li>If <code>keyboardButtonSwitchInline.same_peer</code> is not set, prompt the user to select one of their chats, and then insert the bot's username and <code>keyboardButtonSwitchInline.query</code> in the current chat's input field, triggering an <a href="/api/bots/inline">inline query</a>.</li>
</ul>
</li>
<li><a href="/constructor/keyboardButtonGame">keyboardButtonGame</a> - Open the <a href="/constructor/game">game</a> from the attached <a href="/constructor/messageMediaGame">messageMediaGame</a> constructor, for more info <a href="/api/bots/games">see here »</a></li>
<li><a href="/constructor/keyboardButtonBuy">keyboardButtonBuy</a> - Proceed to initiating the payment flow, for more info <a href="/api/payments">see here »</a></li>
<li><a href="/constructor/keyboardButtonUrlAuth">keyboardButtonUrlAuth</a> - Log into a website using the user's Telegram account, as specified <a href="/api/url-authorization">here »</a></li>
</ul>
<h3><a class="anchor" href="#callback-queries" id="callback-queries" name="callback-queries"><i class="anchor-icon"></i></a>Callback queries</h3>
<p><a href="/constructor/keyboardButtonCallback">keyboardButtonCallback</a> buttons can be used to send the specified <code>data</code> payload back to the bot, when they are clicked.<br>
Additionally, a bot can verify a user's identity by requiring they verify their 2FA password with <a href="/api/srp">SRP</a>. </p>
<h4><a class="anchor" href="#sending-a-callback-query" id="sending-a-callback-query" name="sending-a-callback-query"><i class="anchor-icon"></i></a>Sending a callback query</h4>
<pre><code><a href='/constructor/keyboardButtonGame'>keyboardButtonGame</a>#50f41ccf text:<a href='/type/string'>string</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/keyboardButtonCallback'>keyboardButtonCallback</a>#35bbdb6b flags:<a href='/type/%23'>#</a> requires_password:flags.0?<a href='/constructor/true'>true</a> text:<a href='/type/string'>string</a> data:<a href='/type/bytes'>bytes</a> = <a href='/type/KeyboardButton'>KeyboardButton</a>;
<a href='/constructor/messages.botCallbackAnswer'>messages.botCallbackAnswer</a>#36585ea4 flags:<a href='/type/%23'>#</a> alert:flags.1?<a href='/constructor/true'>true</a> has_url:flags.3?<a href='/constructor/true'>true</a> native_ui:flags.4?<a href='/constructor/true'>true</a> message:flags.0?<a href='/type/string'>string</a> url:flags.2?<a href='/type/string'>string</a> cache_time:<a href='/type/int'>int</a> = <a href='/type/messages.BotCallbackAnswer'>messages.BotCallbackAnswer</a>;
---functions---
<a href='/method/messages.getBotCallbackAnswer'>messages.getBotCallbackAnswer</a>#9342ca07 flags:<a href='/type/%23'>#</a> game:flags.1?<a href='/constructor/true'>true</a> peer:<a href='/type/InputPeer'>InputPeer</a> msg_id:<a href='/type/int'>int</a> data:flags.0?<a href='/type/bytes'>bytes</a> password:flags.2?<a href='/type/InputCheckPasswordSRP'>InputCheckPasswordSRP</a> = <a href='/type/messages.BotCallbackAnswer'>messages.BotCallbackAnswer</a>;</code></pre>
<p>When the user clicks on a <a href="/constructor/keyboardButtonCallback">keyboardButtonCallback</a> in a message sent by a bot, or generated by an <a href="/api/bots/inline">inline query</a>, <a href="/method/messages.getBotCallbackAnswer">messages.getBotCallbackAnswer</a> should be called, passing the peer and ID of the message.<br>
The same should happen when clicking on <a href="/constructor/keyboardButtonGame">keyboardButtonGame</a> buttons, with the difference that the <code>game</code> flag must be set instead of the <code>data</code> parameter. </p>
<p>Make sure to properly handle bot timeouts in the form of <code>BOT_RESPONSE_TIMEOUT</code> RPC errors, as the bot may be offline and unable to reply. </p>
<p>The returned <a href="/constructor/messages.botCallbackAnswer">messages.botCallbackAnswer</a> constructor contains:</p>
<ul>
<li><code>message</code> if specified, a message that should be shown in a non-blocking toast notification</li>
<li><code>alert</code> indicates whether the <code>message</code> should be shown as a dismissible prompt, instead of a simple toast notification</li>
<li><code>has_url</code> Whether an URL is present</li>
<li><code>url</code> if specified, the client should open the URL, without showing a confirmation prompt. <br> This is safe and allowed, because here bots can only return: <ul>
<li><a href="/api/links#bot-links">Deep links to themselves »</a></li>
<li><a href="/api/links#game-links">Deep links to a valid game they own »</a>, if the bot has manually configured games, and the clicked button was a <a href="/constructor/keyboardButtonGame">keyboardButtonGame</a>. </li>
</ul>
</li>
<li><code>native_ui</code> whether to open game URLs in a WebView or in native UI.</li>
<li><code>cache_time</code> specifies for how long should this answer be cached, client-side</li>
</ul>
<h5><a class="anchor" href="#srp-verification" id="srp-verification" name="srp-verification"><i class="anchor-icon"></i></a>SRP verification</h5>
<p>If the <code>requires_password</code> flag is set, the <a href="/api/srp">SRP 2FA payload</a> must also be generated and attached to the query, to verify the identity of the user. </p>
<p><strong>Note that the bot will NOT be able to access your password or the SRP payload</strong>. </p>
<p>The SRP payload will be processed exclusively on the Telegram's servers, simply returning an RPC error without passing the query to the bot if the verification fails.<br>
This is just a way of verifying the identity of the user, mainly used by the official <a href="https://t.me/botfather">@botfather</a> bot to allow securely transferring the ownership of a bot to another user.</p>
<h4><a class="anchor" href="#answering-a-callback-query" id="answering-a-callback-query" name="answering-a-callback-query"><i class="anchor-icon"></i></a>Answering a callback query</h4>
<pre><code><a href='/constructor/updateBotCallbackQuery'>updateBotCallbackQuery</a>#b9cfc48d flags:<a href='/type/%23'>#</a> query_id:<a href='/type/long'>long</a> user_id:<a href='/type/long'>long</a> peer:<a href='/type/Peer'>Peer</a> msg_id:<a href='/type/int'>int</a> chat_instance:<a href='/type/long'>long</a> data:flags.0?<a href='/type/bytes'>bytes</a> game_short_name:flags.1?<a href='/type/string'>string</a> = <a href='/type/Update'>Update</a>;
<a href='/constructor/updateInlineBotCallbackQuery'>updateInlineBotCallbackQuery</a>#691e9052 flags:<a href='/type/%23'>#</a> query_id:<a href='/type/long'>long</a> user_id:<a href='/type/long'>long</a> msg_id:<a href='/type/InputBotInlineMessageID'>InputBotInlineMessageID</a> chat_instance:<a href='/type/long'>long</a> data:flags.0?<a href='/type/bytes'>bytes</a> game_short_name:flags.1?<a href='/type/string'>string</a> = <a href='/type/Update'>Update</a>;
---functions---
<a href='/method/messages.setBotCallbackAnswer'>messages.setBotCallbackAnswer</a>#d58f130a flags:<a href='/type/%23'>#</a> alert:flags.1?<a href='/constructor/true'>true</a> query_id:<a href='/type/long'>long</a> message:flags.0?<a href='/type/string'>string</a> url:flags.2?<a href='/type/string'>string</a> cache_time:<a href='/type/int'>int</a> = <a href='/type/Bool'>Bool</a>;</code></pre>
<p>After the user invokes <a href="/method/messages.getBotCallbackAnswer">messages.getBotCallbackAnswer</a>, an <a href="/constructor/updateBotCallbackQuery">updateBotCallbackQuery</a> or <a href="/constructor/updateInlineBotCallbackQuery">updateInlineBotCallbackQuery</a> is generated and sent to the bot, depending on whether the query originated from a normal message sent by the bot, or from a message sent from an <a href="/api/bots/inline">inline query</a>. </p>
<p>Either way, bots must reply to the query as quickly as possible using <a href="/method/messages.setBotCallbackAnswer">messages.setBotCallbackAnswer</a>: </p>
<ul>
<li><code>query_id</code> is the <code>query_id</code> from <a href="/method/messages.getBotCallbackAnswer">messages.getBotCallbackAnswer</a>, an <a href="/constructor/updateBotCallbackQuery">updateBotCallbackQuery</a> or <a href="/constructor/updateInlineBotCallbackQuery">updateInlineBotCallbackQuery</a></li>
<li><code>message</code>, <code>alert</code>, <code>url</code> can contain messages and URLs to trigger different client behaviour, as <a href="#sending-a-callback-query">specified above »</a></li>
<li><code>cache_time</code> indicates the maximum amount of time in seconds that the result of the callback query may be cached by the <strong>client</strong>. </li>
</ul>
<p>If a <code>game_short_name</code> is present in the update, the bot should return the URL of the game with the specified name.<br>
The <a href="/method/messages.setBotCallbackAnswer">messages.setBotCallbackAnswer</a> method must be called anyway, even if no <code>message</code> or <code>url</code> is returned, to avoid timeouts on the client.</p></div>
</div>
</div>
</div>
<div class="footer_wrap">
<div class="footer_columns_wrap footer_desktop">
<div class="footer_column footer_column_telegram">
<h5>Telegram</h5>
<div class="footer_telegram_description"></div>
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.
</div>
<div class="footer_column">
<h5><a href="//telegram.org/faq">About</a></h5>
<ul>
<li><a href="//telegram.org/faq">FAQ</a></li>
<li><a href="//telegram.org/privacy">Privacy</a></li>
<li><a href="//telegram.org/press">Press</a></li>
</ul>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/apps#mobile-apps">Mobile Apps</a></h5>
<ul>
<li><a href="//telegram.org/dl/ios">iPhone/iPad</a></li>
<li><a href="//telegram.org/android">Android</a></li>
<li><a href="//telegram.org/dl/web">Mobile Web</a></li>
</ul>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/apps#desktop-apps">Desktop Apps</a></h5>
<ul>
<li><a href="//desktop.telegram.org/">PC/Mac/Linux</a></li>
<li><a href="//macos.telegram.org/">macOS</a></li>
<li><a href="//telegram.org/dl/web">Web-browser</a></li>
</ul>
</div>
<div class="footer_column footer_column_platform">
<h5><a href="/">Platform</a></h5>
<ul>
<li><a href="/api">API</a></li>
<li><a href="//translations.telegram.org/">Translations</a></li>
<li><a href="//instantview.telegram.org/">Instant View</a></li>
</ul>
</div>
</div>
<div class="footer_columns_wrap footer_mobile">
<div class="footer_column">
<h5><a href="//telegram.org/faq">About</a></h5>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/blog">Blog</a></h5>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/apps">Apps</a></h5>
</div>
<div class="footer_column">
<h5><a href="/">Platform</a></h5>
</div>
<div class="footer_column">
<h5><a href="//telegram.org/press">Press</a></h5>
</div>
</div>
</div>
</div>
<script src="/js/main.js?47"></script>
<script src="/js/jquery.min.js?1"></script>
<script src="/js/bootstrap.min.js?1"></script>
<script>window.initDevPageNav&&initDevPageNav();
backToTopInit("Go up");
removePreloadInit();
</script>
</body>
</html>