发送消息
向用户或群组发送消息。
接口信息
| 属性 | 值 |
|---|---|
| 请求方式 | POST |
| 请求路径 | /v1/message/send |
| 鉴权方式 | App Token / User Token |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| receive_id | string | 是 | 接收者 ID |
| receive_type | string | 是 | 接收者类型:user / group |
| msg_type | string | 是 | 消息类型:text / image / file / card |
| content | object | 是 | 消息内容 |
content 结构
文本消息
{
"text": "消息内容",
"mentions": ["user_001"] // 可选,@的用户列表
}
图片消息
{
"image_key": "img_xxxxxx"
}
卡片消息
{
"header": {
"title": "标题",
"template": "blue"
},
"elements": [...]
}
请求示例
curl -X POST 'https://api.im.example.com/v1/message/send' \
-H 'Authorization: Bearer t-xxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"receive_id": "user_001",
"receive_type": "user",
"msg_type": "text",
"content": {
"text": "您有一条新的审批待处理"
}
}'
响应参数
| 参数 | 类型 | 说明 |
|---|---|---|
| message_id | string | 消息 ID |
响应示例
{
"code": 0,
"msg": "success",
"data": {
"message_id": "msg_xxxxxx"
}
}
错误码
| 错误码 | 说明 |
|---|---|
| 10301 | 接收者不存在 |
| 10302 | 无发送权限 |
| 10303 | 消息内容格式错误 |
| 10304 | 消息内容超长 |