<p>Users can interact with your bot via <ahref="/bots/#inline-mode"><strong>inline queries</strong></a>, straight from the <strong>text input field</strong> in <strong>any</strong> chat.<br>
This article describes the full inline bot flow, using the MTProto API. </p>
<p>For a simplified description using the HTTP bot API, see <ahref="/bots/#inline-mode">here »</a>. </p>
<h3><aclass="anchor"href="#making-an-inline-query"id="making-an-inline-query"name="making-an-inline-query"><iclass="anchor-icon"></i></a>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>bot</code> - The bot peer</li>
<li><code>peer</code> - The chat where the user made the query</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>
</ul>
</li>
</ul>
<h3><aclass="anchor"href="#answering-to-an-inline-query"id="answering-to-an-inline-query"name="answering-to-an-inline-query"><iclass="anchor-icon"></i></a>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="#sending-the-inline-query-result">chosen</a>, generates a message with optionally attached media, and even inline buttons.</p>
<h3><aclass="anchor"href="#sending-the-inline-query-result"id="sending-the-inline-query-result"name="sending-the-inline-query-result"><iclass="anchor-icon"></i></a>Sending the inline query result</h3>
<p>The user client should display the <code>results</code> obtained <ahref="#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 the user then chooses a specific <code>BotInlineResult</code>, the <ahref="/method/messages.sendInlineBotResult">messages.sendInlineBotResult</a> method should be invoked, passing:</p>
<ul>
<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="#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>
</ul>
<h3><aclass="anchor"href="#editing-sent-inline-messages"id="editing-sent-inline-messages"name="editing-sent-inline-messages"><iclass="anchor-icon"></i></a>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.