The short answer
- 1@yourbot plus a query shows your results in any chat, without adding the bot.
- 2Turn it on with /setinline in @BotFather and set a placeholder.
- 3Answer each inline_query quickly with answerInlineQuery, up to 50 results.
In this article
What inline mode does
In any chat, a user types @yourbot and a search word in the message field. Your bot shows a list of results above the field, and the one they pick is sent straight into that chat. Your bot does not have to be a member of the chat. Inline mode suits "find it and paste it" jobs such as GIF search, translation or sharing links. For how this looks to users, see using inline bots without adding them.
Turn it on in @BotFather
- Choose your bot and turn on inline mode with
/setinline. - Set the placeholder, the grey hint shown in the message field, for example "Search GIFs…".
- Optionally turn on
/setinlinegeoto receive the user's location with each query, and/setinlinefeedbackto learn which result they picked.
Receive a query and answer it
As the user types, your bot receives inline_query updates (see webhooks vs long polling). Each one has the search text in query and an id. Reply with answerInlineQuery using that ID:
curl https://api.telegram.org/bot123456:ABC-EXAMPLE/answerInlineQuery \
-H "Content-Type: application/json" \
-d '{"inline_query_id":"QUERY_ID",
"results":[{"type":"article","id":"1","title":"Say hello",
"input_message_content":{"message_text":"Hello there"}}],
"cache_time":60}'
| Field | Meaning |
|---|---|
results | Up to 50 per answer; there are formats for articles, photos, GIFs, videos, stickers and more |
cache_time | How many seconds Telegram's servers keep the results for the same query; the default is 300 |
is_personal | Cache separately for each user, when results differ from person to person |
next_offset | Marks that more results exist; when the user scrolls to the end you are asked again with this value |
Answer inline queries fast
Users expect results while they are still typing. If your answer is slow, nothing appears. Prepare heavy searches in advance, set a sensible cache_time for common queries, and have default results ready for when the query is empty, that is, when the user has typed only @yourbot.
Other things worth knowing
- Which result was chosen: with feedback on, the picked result arrives as
chosen_inline_result, useful for statistics. - Starting from a button: an inline button with
switch_inline_querylets the user pick a chat and opens inline mode there; see bot buttons. - Groups can block it: a group's permissions can stop members from using inline bots, and then your results cannot be sent there.
FAQ
How do I enable inline mode for my Telegram bot?
Send /setinline to @BotFather, choose your bot and set the placeholder text.
How many results can an inline bot return?
Up to 50 per answer. Use next_offset to load more when the user scrolls.
Why are my inline results not showing?
Usually the answer is too slow, or answerInlineQuery failed. Answer fast and keep default results for an empty query.
Sources
At a glance
- 1Enable
/setinline, plus optional geo and feedback.
- 2Answer
answerInlineQuery with the query id; cache_time defaults to 300 s.
- 3Privacy
Use is_personal when results depend on the user.
Updated