editMessageReplyMarkup
编辑已发送消息的回复标记(内联键盘)。仅修改键盘部分,不影响消息文本内容。
请求
POST /:token/editMessageReplyMarkup
参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| chat_id | Integer/String | 条件必填 | 目标聊天的唯一标识符或用户名。若未指定 inline_message_id 则必填 |
| message_id | Integer | 条件必填 | 要编辑的消息 ID。若未指定 inline_message_id 则必填 |
| inline_message_id | String | 条件必填 | 内联消息的标识符。若未指定 chat_id 和 message_id 则必填 |
| reply_markup | Object | 否 | 新的内联键盘标记,JSON 序列化对象。不传或传空对象则移除现有键盘 |
响应
返回编辑后的 Message 对象。
json
{
"ok": true,
"result": {
"message_id": 100,
"from": {
"id": 123456789,
"is_bot": true,
"first_name": "MyBot",
"username": "my_bot"
},
"chat": {
"id": 987654321,
"first_name": "User",
"username": "user123",
"type": "private"
},
"date": 1700000000,
"edit_date": 1700000120,
"text": "请选择一个选项:",
"reply_markup": {
"inline_keyboard": [
[
{"text": "新选项 A", "callback_data": "new_a"},
{"text": "新选项 B", "callback_data": "new_b"}
]
]
}
}
}错误码
| 错误码 | 描述 |
|---|---|
| 400 | 请求参数错误,如 reply_markup 格式不正确或键盘未发生变化 |
| 401 | Token 无效或已过期 |
| 403 | Bot 无权编辑该消息(只能编辑 Bot 自己发送的消息) |
| 404 | 消息不存在 |
| 500 | 服务器内部错误 |
示例
更新内联键盘
bash
curl -X POST "https://api.example.com/<token>/editMessageReplyMarkup" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"message_id": 100,
"reply_markup": {
"inline_keyboard": [
[
{"text": "新选项 A", "callback_data": "new_a"},
{"text": "新选项 B", "callback_data": "new_b"}
],
[
{"text": "取消", "callback_data": "cancel"}
]
]
}
}'移除内联键盘
bash
curl -X POST "https://api.example.com/<token>/editMessageReplyMarkup" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"message_id": 100,
"reply_markup": {}
}'