You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telegram机器人调用sendMessage发送内联键盘失败求助

Telegram Bot sendMessage接口内联键盘不显示的解决办法

问题描述

调用Telegram Bot API的sendMessage接口发送带内联键盘的消息时,仅文本内容“test”发送成功,但内联键盘未显示。请求参数及接口地址如下:

请求参数:

{
    "chat_id": "-1001751031382",
    "text": "test",
    "parse_mode": "Markdown",
    "disable_web_page_preview": true,
    "replay_markup": {
        "inline_keyboard": [
            [
                {
                    "text": "text1",
                    "url": "https://ali-qorbani.ir/1"
                },
                {
                    "text": "text2",
                    "url": "https://ali-qorbani.ir/2"
                }
            ],
            [
                {
                    "text": "start",
                    "url": "https://ali-qorbani.ir/4"
                }
            ]
        ]
    }
}

接口地址:https://api.telegram.org/bot{{token}}/sendMessage

解决方案

1. 修正参数名拼写错误

核心问题是参数名拼写错误:你将reply_markup误写为replay_markup,Telegram API无法识别这个错误参数,因此不会渲染内联键盘。

修正后的请求参数:

{
    "chat_id": "-1001751031382",
    "text": "test",
    "parse_mode": "Markdown",
    "disable_web_page_preview": true,
    "reply_markup": {
        "inline_keyboard": [
            [
                {
                    "text": "text1",
                    "url": "https://ali-qorbani.ir/1"
                },
                {
                    "text": "text2",
                    "url": "https://ali-qorbani.ir/2"
                }
            ],
            [
                {
                    "text": "start",
                    "url": "https://ali-qorbani.ir/4"
                }
            ]
        ]
    }
}

2. 额外检查项

如果修正拼写后仍未显示键盘,可排查以下内容:

  • 确保请求使用POST方法,且请求头设置Content-Type: application/json(若通过JSON格式传递参数)
  • 确认{{token}}已替换为你的Bot的有效令牌
  • 检查inline_keyboard的结构是否符合要求:每个子数组代表一行按钮,按钮对象的text和url字段是否完整且格式正确

内容的提问来源于stack exchange,提问作者Ali Qorbani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 21:40:57