sendMessage
Send a text message to a specified chat.
Request
POST /:token/sendMessage
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Unique identifier or username of the target chat |
| text | String | Yes | Text content of the message |
| parse_mode | String | No | Text parsing mode, supports HTML or Markdown |
| reply_markup | Object | No | Custom keyboard or inline keyboard markup, JSON-serialized object |
| reply_to_message_id | Integer | No | ID of the message to reply to. When set, the message will be sent as a quoted reply |
Response
Returns the sent 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,
"text": "Hello, World!"
}
}Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters, e.g. missing text or chat_id |
| 401 | Invalid or expired token |
| 403 | Bot was blocked by the user or does not have permission to send messages to this chat |
| 404 | Chat not found |
| 500 | Internal server error |
Examples
cURL
bash
curl -X POST "https://api.example.com/<token>/sendMessage" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"text": "Hello, World!",
"parse_mode": "HTML"
}'Message with Inline Keyboard
bash
curl -X POST "https://api.example.com/<token>/sendMessage" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"text": "Please choose an option:",
"reply_markup": {
"inline_keyboard": [
[
{"text": "Option A", "callback_data": "option_a"},
{"text": "Option B", "callback_data": "option_b"}
]
]
}
}'Reply to a Message
bash
curl -X POST "https://api.example.com/<token>/sendMessage" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"text": "This is a reply",
"reply_to_message_id": 99
}'