Skip to content

机器人发送消息

请求URL

https://chat-go.jwzhd.com/open-apis/v1/bot/send?token=016ec8e4d17a4fbda3ccb0e99b44aca0

请求类型

POST

请求头

bash
Content-Type: "application/json"

请求参数

字段类型是否必填说明
recvIdstring接收消息对象ID
用户: userId
群: groupId
recvTypestring接收对象类型
用户: user
群: group
contentTypestring消息类型,取值如下
text/image/video/file/markdown/html (html支持标签
contentContent对象消息对象
parentIdstring引用消息 ID
Content对象

contentType为text

字段类型是否必填说明
textstring消息正文
atstring数组被at的用户ID列表
buttonsButton对象列表消息中包括button
content.at字段说明

当需要在消息中@用户时,需要在content对象中添加at字段。

at字段是一个字符串数组,包含被@用户的ID列表。

重要规则:

  1. at字段是一个唯一数组,按顺序排列
  2. 消息中的@用户格式为:@用户名+零宽空格
  3. 零宽空格(U+200B)用于标记@用户的结束位置
  4. 不能使用空格作为@结束标志,因为用户名可能包含空格

示例:

json
{
  "recvId": "307149245",
  "recvType": "group",
  "contentType": "text",
  "content": {
    "text": "@小学不在这里哦​ 你好啊!我at你了",
    "at": [
      "7756242"
    ]
  }
}

多用户@示例:

json
{
  "recvId": "307149245",
  "recvType": "group",
  "contentType": "text",
  "content": {
    "text": "你好@小学云bot ​,我饿了@小学不在这里哦 ​,一起去吃饭吧@小学云bot ​。",
    "at": [
      "37090343",
      "7756242"
    ]
  }
}

带空格的用户名@示例:

json
{
  "recvId": "307149245",
  "recvType": "group",
  "contentType": "text",
  "content": {
    "text": "@yunhu test bot ​你好啊",
    "at": [
      "86297657"
    ]
  }
}

解析结果: 上述带空格用户名的示例 会被本适配器解析为:

html
<at id="86297657" name="yunhu test bot "/>你好啊

contentType为image

字段类型是否必填说明
imageKeystring图片Key, 通过图片上传接口获得
buttonsButton对象列表消息中包括button

contentType为markdown

字段类型是否必填说明
textstringmarkdown字符串
buttonsButton对象列表消息中包括button

contentType为file

字段类型是否必填说明
fileKeystring文件Key, 通过文件上传接口获得
buttonsButton对象列表消息中包括button

contentType为video

字段类型是否必填说明
videoKeystring视频Key, 通过视频上传接口获得
buttonsButton对象列表消息中包括button
Button对象
字段类型是否必填说明
textstring按钮上的文字
actionTypeint1: 跳转URL
2: 复制
3: 点击汇报
urlstring当actionType为1时使用
valuestring当actionType为2时,该值会复制到剪贴板
当actionType为3时,该值会发送给订阅端

响应内容

字段类型说明
codeint响应代码
msgstring响应信息,包括异常信息
dataObject返回数据

完整示例

请求示例

bash
curl --location 'https://chat-go.jwzhd.com/open-apis/v1/bot/send?token=016ec8e4d17a4fbda3ccb0e99b44aca0' \
--header 'Content-Type: application/json' \
--data '{
    "recvId": "307149245",
    "recvType": "group",
    "contentType": "text",
    "content": {
        "text": "这里是消息内容",
        "buttons": [
            [
                {
                    "text": "复制",
                    "actionType": 2,
                    "value": "xxxx"
                },
                {
                    "text": "点击跳转",
                    "actionType": 1,
                    "url": "http://www.baidu.com"
                }
            ]
        ]
    }
}'

发送文本消息请求示例

json
{
    "recvId": "307149245",
    "recvType": "group",
    "contentType": "text",
    "content": {
        "text": "这里是消息内容",
        "buttons": [
            [
                {
                    "text": "复制",
                    "actionType": 2,
                    "value": "xxxx"
                },
                {
                    "text": "点击跳转",
                    "actionType": 1,
                    "url": "http://www.baidu.com"
                }
            ]
        ]
    }
}

发送带@用户的文本消息请求示例

json
{
    "recvId": "307149245",
    "recvType": "group",
    "contentType": "text",
    "content": {
        "text": "@小学不在这里哦​ 你好啊!我at你了",
        "at": [
            "7756242"
        ]
    }
}

发送带多个@用户的文本消息请求示例

json
{
    "recvId": "307149245",
    "recvType": "group",
    "contentType": "text",
    "content": {
        "text": "你好@小学云bot ​,我饿了@小学不在这里哦 ​,一起去吃饭吧@小学云bot ​。",
        "at": [
            "37090343",
            "7756242"
        ]
    }
}

响应内容

json
{
    "code": 1,
    "data": {
        "messageInfo": {
            "msgId": "a54ec67c089044dfa4241b9dd0a57f8d",
            "recvId": "307149245",
            "recvType": "group"
        }
    },
    "msg": "success"
}