editMessageReplyMarkup
Edit the reply markup (inline keyboard) of a previously sent message. Only modifies the keyboard; the message text content remains unchanged.
Request
POST /:token/editMessageReplyMarkup
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Unique identifier or username of the target chat |
| message_id | Integer | Yes | ID of the message to edit |
| reply_markup | Object | No | New inline keyboard markup, JSON-serialized object. Omitting this parameter or passing an empty object will remove the existing keyboard |
Response
Returns the edited Message object on success.
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": "Please choose an option:",
"reply_markup": {
"inline_keyboard": [
[
{"text": "New Option A", "callback_data": "new_a"},
{"text": "New Option B", "callback_data": "new_b"}
]
]
}
}
}Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters, e.g. invalid reply_markup format or keyboard is unchanged |
| 401 | Invalid or expired token |
| 403 | Bot does not have permission to edit this message (can only edit messages sent by the Bot itself) |
| 404 | Message not found |
| 500 | Internal server error |
Examples
Update Inline Keyboard
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": "New Option A", "callback_data": "new_a"},
{"text": "New Option B", "callback_data": "new_b"}
],
[
{"text": "Cancel", "callback_data": "cancel"}
]
]
}
}'Remove Inline Keyboard
bash
curl -X POST "https://api.example.com/<token>/editMessageReplyMarkup" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"message_id": 100,
"reply_markup": {}
}'