sendDocument
发送文档文件到指定聊天。支持直接上传文件或传入已有文件的 file_id。适用于发送各类文件,最大支持 100MB。
请求
POST /:token/sendDocument
文件上传时使用 multipart/form-data 编码。
参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| chat_id | Integer/String | 是 | 目标聊天的唯一标识符或用户名 |
| document | String/File | 是 | 文档文件或已上传文件的 file_id,最大 100MB |
| caption | String | 否 | 文档说明文字 |
| parse_mode | String | 否 | 说明文字的解析模式,支持 HTML 或 Markdown |
| reply_markup | Object | 否 | 自定义键盘或内联键盘标记,JSON 序列化对象 |
响应
返回发送成功的 Message 对象。
json
{
"ok": true,
"result": {
"message_id": 105,
"from": {
"id": 123456789,
"is_bot": true,
"first_name": "MyBot",
"username": "my_bot"
},
"chat": {
"id": 987654321,
"first_name": "User",
"username": "user123",
"type": "private"
},
"date": 1700000000,
"document": {
"file_id": "BQACAgIAAxkBAAI...",
"file_unique_id": "AQADAgAT...",
"file_name": "report.pdf",
"mime_type": "application/pdf",
"file_size": 524288
},
"caption": "这是一份报告文档"
}
}错误码
| 错误码 | 描述 |
|---|---|
| 400 | 请求参数错误,如缺少 document 或 chat_id |
| 401 | Token 无效或已过期 |
| 403 | Bot 无权向该聊天发送消息 |
| 404 | 聊天不存在 |
| 413 | 文件体积过大(超过 100MB) |
| 500 | 服务器内部错误 |
示例
通过文件上传发送文档
bash
curl -X POST "https://api.example.com/<token>/sendDocument" \
-F "chat_id=987654321" \
-F "document=@/path/to/report.pdf" \
-F "caption=这是一份报告文档"通过 file_id 发送文档
bash
curl -X POST "https://api.example.com/<token>/sendDocument" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 987654321,
"document": "BQACAgIAAxkBAAI...",
"caption": "转发一份文档"
}'