Skip to content

answerInlineQuery

回复内联查询。当用户在任意聊天的输入框中输入 @bot用户名 关键词 时,Bot 会通过 getUpdates 或 Webhook 收到 inline_query 更新,需调用本方法返回结果列表供用户选择。

当前版本支持 article(文章/文本)和 game(游戏)两种结果类型,其他类型会被忽略。

请求

POST /:token/answerInlineQuery

参数

参数类型必填描述
inline_query_idString要应答的内联查询唯一标识符,来自 inline_query.id
resultsInlineQueryResult[]结果对象的 JSON 序列化数组,支持 articlegame 两种类型
cache_timeInteger结果在服务端的缓存时间(秒),默认 300

is_personalnext_offsetswitch_pm_textswitch_pm_parameter 等 Telegram 官方参数当前版本可以传入但不会生效。

结果类型

InlineQueryResultArticle

字段类型必填描述
typeString固定为 article
idString结果的唯一标识符
titleString结果标题
descriptionString结果的简短描述
input_message_contentObject用户选中后要发送的消息内容,当前仅支持 message_text 字段(纯文本)

InlineQueryResultGame

字段类型必填描述
typeString固定为 game
idString结果的唯一标识符
game_short_nameString游戏的短名称,见小游戏概览

结果对象中的 reply_markup 当前不支持自定义;游戏卡片的默认按钮由服务端自动补齐。

响应

成功时返回 Boolean 值 true

json
{
  "ok": true,
  "result": true
}

用户选中某个结果后,对应消息会以用户的名义发送到该聊天;Bot 可通过 chosen_inline_result 更新获知用户的选择。

错误码

错误码描述
400请求参数错误,如 inline_query_id 无效、不属于当前 Bot,或 results 不是合法的 JSON 数组
401Token 无效或已过期
500服务器内部错误

示例

返回文章结果

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": "今日天气",
        "description": "晴,28°C",
        "input_message_content": {"message_text": "今日天气:晴,28°C"}
      }
    ],
    "cache_time": 60
  }'

返回游戏结果

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