<p>Users can interact with your bot via <ahref="/bots/features#inline-requests"><strong>inline queries</strong></a>, straight from the <strong>text input field</strong> in <strong>any</strong> chat.<br>
<h3><aclass="anchor"href="#1-making-an-inline-query"id="1-making-an-inline-query"name="1-making-an-inline-query"><iclass="anchor-icon"></i></a>1. Making an inline query</h3>
<p>When, in a graphical client, the user starts a message with an <code>@</code>, clients should:</p>
<ul>
<li>Use the cached <ahref="/api/top-rating">top peer rating for inline bots</a> to show a list of frequently used inline bots.</li>
<li>If the user chooses a bot from the recent bot list or:</li>
<li>Finishes typing a full username followed by a whitespace, and if the username <ahref="/method/contacts.resolveUsername">resolves</a> to a valid bot</li>
<li><ahref="/method/messages.getInlineBotResults">messages.getInlineBotResults</a> is called, with the following parameters:<ul>
<li><code>peer</code> - The chat where the user made the query (or <ahref="/constructor/inputPeerEmpty">inputPeerEmpty</a> for <ahref="/api/gifs">GIF searches</a> and other queries to built-in bots specified in the <ahref="/constructor/config">config</a>)</li>
<li><code>geo_point</code> - The user's current geolocation, if the bot requires <ahref="/bots/inline#location-based-results">location-based inline results</a> (the <code>bot_inline_geo</code> flag of the bot's <ahref="/constructor/user">user constructor</a> will be set)</li>
<li><code>query</code> - What the user typed after the bot's username</li>
<li><code>offset</code> - If the user scrolls past the first <code>len(results)</code> results, and <code>next_offset</code> field is set, the inline query should be repeated with this offset.</li>
<h3><aclass="anchor"href="#2-answering-to-an-inline-query"id="2-answering-to-an-inline-query"name="2-answering-to-an-inline-query"><iclass="anchor-icon"></i></a>2. Answering to an inline query</h3>
<p>Bots can answer to incoming <ahref="/constructor/updateBotInlineQuery">updateBotInlineQuery</a> updates using <ahref="/method/messages.setInlineBotResults">messages.setInlineBotResults</a>.<br>
Just like its <ahref="/bots/api#answerinlinequery">bot API counterpart</a>, the method can be used to send a set of inline results to the user; see the <ahref="/method/messages.setInlineBotResults">constructor page for more info on the MTProto method parameters»</a>.</p>
<p>In general, the method accepts a vector of <ahref="/type/InputBotInlineResult">InputBotInlineResult</a> constructors, that when <ahref="#3-sending-the-inline-query-result">chosen</a>, generates a message with optionally attached media, and even inline buttons.</p>
<h3><aclass="anchor"href="#3-sending-the-inline-query-result"id="3-sending-the-inline-query-result"name="3-sending-the-inline-query-result"><iclass="anchor-icon"></i></a>3. Sending the inline query result</h3>
<p>The user client should display the <ahref="/constructor/messages.botResults">messages.botResults</a>.<code>results</code> obtained <ahref="#1-making-an-inline-query">during querying</a> in a list, making sure to handle eventual bot timeouts in the form of a <code>BOT_RESPONSE_TIMEOUT</code> RPC error, by simply not displaying anything. </p>
<p>If either the <ahref="/constructor/messages.botResults">messages.botResults</a>.<code>switch_pm</code> or <ahref="/constructor/messages.botResults">messages.botResults</a>.<code>switch_webview</code> flags are populated, a button should be displayed on top of the result list, that when clicked, instead of sending an inline result to the chat, switches the user to a private chat with the bot (<code>switch_pm</code>) or to a <ahref="/api/bots/webapps#inline-mode-mini-apps">inline mode mini app</a> (<code>switch_webview</code>). </p>
<p>If the user instead chooses a specific <code>BotInlineResult</code> from the normal <code>results</code> list, the <ahref="/method/messages.sendInlineBotResult">messages.sendInlineBotResult</a> method should be invoked, passing:</p>
<li>The <code>query_id</code> from <code>messages.botResults</code></li>
<li>The <code>id</code> of the chosen result</li>
<li>The <code>peer</code> where to send the chosen result</li>
</ul>
<p>The resulting <ahref="/constructor/message">message</a> will have the <code>via_bot_id</code> field set, to indicate that the result was generated by the bot that generated the inline result.<br>
Graphical clients should display the bot <code>@username</code> in the header of the message, allowing the user to click on it, automatically starting an inline query by inserting <code>@username</code> in the text bar.</p>
<p>If <ahref="/bots/inline#collecting-feedback">feedback collection</a> is enabled, the bot may receive an <ahref="/constructor/updateBotInlineSend">updateBotInlineSend</a> when the user <ahref="#3-sending-the-inline-query-result">chooses and sends</a> an inline result. </p>
<p>Even if the <ahref="/bots/inline#collecting-feedback">probability setting is set to 100%</a>, not all inline results may be reported due to caching (see the <code>cache_time</code> parameter in <ahref="/api/bots/buttons#answering-a-callback-query">Answering a callback query</a>).<br>
<ahref="/bots/inline#collecting-feedback">Feedback collection</a> can also create load issues for popular bots, so adjust the probability setting to a lower value in such cases.</p>
<p>Either way, feedback collection should only be used for statistical purposes rather than functional. </p>
<p>The <ahref="/constructor/updateBotInlineSend">updateBotInlineSend</a> will contain: </p>
<ul>
<li><code>id</code> - The ID of the chosen result</li>
<li><code>msg_id</code> - The ID of the sent inline message</li>
<li><code>user_id</code> - The ID of the user that chose the result</li>
<li><code>query</code> - The query string that was used to obtain the result</li>
<li><code>geo</code> - For bots requiring <ahref="/bots/inline#location-based-results">location-based inline results</a>, the user's location</li>
<h3><aclass="anchor"href="#5-editing-sent-inline-messages"id="5-editing-sent-inline-messages"name="5-editing-sent-inline-messages"><iclass="anchor-icon"></i></a>5. Editing sent inline messages</h3>
<p>Sent inline messages can be edited by the bot, for example in response to a <ahref="/api/bots/buttons#callback-queries">button press callback query</a>. </p>
<p>Simply pass the <ahref="/constructor/inputBotInlineMessageID">inputBotInlineMessageID</a> specified in the <ahref="/constructor/updateInlineBotCallbackQuery">updateInlineBotCallbackQuery</a> to <ahref="/method/messages.editInlineBotMessage">messages.editInlineBotMessage</a> along with the new message, making sure to send the query to the <ahref="/api/datacenter">datacenter</a> specified in <code>inputBotInlineMessageID.dc_id</code>.</p></div>
</div>
</div>
</div>
<divclass="footer_wrap">
<divclass="footer_columns_wrap footer_desktop">
<divclass="footer_column footer_column_telegram">
<h5>Telegram</h5>
<divclass="footer_telegram_description"></div>
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.