answerInlineQuery
Answer an inline query. When a user types @botusername keywords in the input box of any chat, the bot receives an inline_query update via getUpdates or Webhook, and must call this method to return a list of results for the user to choose from.
The current version supports two result types: article (text) and game. Other types are ignored.
Request
POST /:token/answerInlineQuery
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| inline_query_id | String | Yes | Unique identifier of the inline query to answer, taken from inline_query.id |
| results | InlineQueryResult[] | Yes | JSON-serialized array of result objects; article and game types are supported |
| cache_time | Integer | No | Time in seconds the results are cached on the server, defaults to 300 |
The official Telegram parameters
is_personal,next_offset,switch_pm_textandswitch_pm_parameterare accepted but have no effect in the current version.
Result Types
InlineQueryResultArticle
| Field | Type | Required | Description |
|---|---|---|---|
| type | String | Yes | Must be article |
| id | String | Yes | Unique identifier of the result |
| title | String | Yes | Title of the result |
| description | String | No | Short description of the result |
| input_message_content | Object | Yes | Content of the message to be sent when the result is chosen; currently only the message_text field (plain text) is supported |
InlineQueryResultGame
| Field | Type | Required | Description |
|---|---|---|---|
| type | String | Yes | Must be game |
| id | String | Yes | Unique identifier of the result |
| game_short_name | String | Yes | Short name of the game, see Games Overview |
Custom
reply_markupon result objects is not supported yet; the default button of a game card is added by the server automatically.
Response
Returns Boolean true on success.
{
"ok": true,
"result": true
}After the user chooses a result, the corresponding message is sent to the chat on behalf of the user; the bot can learn about the choice via the chosen_inline_result update.
Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters, e.g. inline_query_id is invalid, does not belong to this bot, or results is not a valid JSON array |
| 401 | Invalid or expired token |
| 500 | Internal server error |
Examples
Answer with an Article
curl -X POST "https://api.safew.bot/<token>/answerInlineQuery" \
-H "Content-Type: application/json" \
-d '{
"inline_query_id": "284861963386739430",
"results": [
{
"type": "article",
"id": "1",
"title": "Weather Today",
"description": "Sunny, 28°C",
"input_message_content": {"message_text": "Weather today: sunny, 28°C"}
}
],
"cache_time": 60
}'Answer with a Game
curl -X POST "https://api.safew.bot/<token>/answerInlineQuery" \
-H "Content-Type: application/json" \
-d '{
"inline_query_id": "284861963386739430",
"results": [
{
"type": "game",
"id": "1",
"game_short_name": "my_game"
}
]
}'