跳到主要内容

发送消息

向用户或群组发送消息。

接口信息​

属性值
请求方式POST
请求路径/v1/message/send
鉴权方式App Token / User Token

请求参数​

参数类型必填说明
receive_idstring是接收者 ID
receive_typestring是接收者类型:user / group
msg_typestring是消息类型:text / image / file / card
contentobject是消息内容

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_idstring消息 ID

响应示例​

{
"code": 0,
"msg": "success",
"data": {
"message_id": "msg_xxxxxx"
}
}

错误码​

错误码说明
10301接收者不存在
10302无发送权限
10303消息内容格式错误
10304消息内容超长