Skip to content

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

ParameterTypeRequiredDescription
inline_query_idStringYesUnique identifier of the inline query to answer, taken from inline_query.id
resultsInlineQueryResult[]YesJSON-serialized array of result objects; article and game types are supported
cache_timeIntegerNoTime in seconds the results are cached on the server, defaults to 300

The official Telegram parameters is_personal, next_offset, switch_pm_text and switch_pm_parameter are accepted but have no effect in the current version.

Result Types

InlineQueryResultArticle

FieldTypeRequiredDescription
typeStringYesMust be article
idStringYesUnique identifier of the result
titleStringYesTitle of the result
descriptionStringNoShort description of the result
input_message_contentObjectYesContent of the message to be sent when the result is chosen; currently only the message_text field (plain text) is supported

InlineQueryResultGame

FieldTypeRequiredDescription
typeStringYesMust be game
idStringYesUnique identifier of the result
game_short_nameStringYesShort name of the game, see Games Overview

Custom reply_markup on 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.

json
{
  "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

CodeDescription
400Bad request parameters, e.g. inline_query_id is invalid, does not belong to this bot, or results is not a valid JSON array
401Invalid or expired token
500Internal server error

Examples

Answer with an Article

bash
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

bash
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"
      }
    ]
  }'