接收消息
事件描述
机器人接收到用户发送的消息后触发此事件:
- 与机器人单聊的消息
- 群聊中@机器人的消息
目前仅支持接收的消息类型:普通文本、回复消息、图片、表情、图文混排、文件
订阅说明
事件主体 | wps.open.xz.message |
---|---|
回调地址 | 请先在开发者后台-事件订阅 模块配置地址 前往配置 (opens new window) |
支持应用类型 | 企业自建应用、第三方企业应用 |
权限要求 | 获取用户发给机器人的单聊消息(xz_message.user2bot.read) 、获取用户在群聊中@机器人的消息(xz_message.group2bot.read) |
解密方式 | 详见 解密算法 |
事件体(解密前)
名称 | 类型 | 说明 |
---|---|---|
topic | string | 消息主题(值为"wps.open.xz.message") |
operation | string | 消息变更动作(创建:create) |
time | integer | 时间(秒为单位的时间戳) |
nonce | string | iv 向量(解密时使用) |
signature | string | 消息签名 |
encrypted_data | string | 消息变更的加密字段 |
事件体示例(解密前)
{
"topic": "wps.open.xz.message",
"operation": "create",
"nonce": "xxxxxx",
"signature": "xxxxxxxxxxxx",
"time": 0, // 秒为单位的时间戳
"encrypted_data": "xxxxxx"
}
事件体(解密后)
名称 | 类型 | 说明 |
---|---|---|
chat_id | integer | 会话 id |
chat_type | integer | 会话类型:2-群聊,3-单聊 |
company_id | string | 会话归属企业 id |
sender | object | 发送者信息 |
∟ company_uid | string | 发送者用户 id |
∟ company_id | string | 发送者归属企业 id |
send_time | integer | 消息发送时间 |
message_id | integer | 消息 id |
message_type | integer | 消息类型 |
content | object | 消息内容,不同消息类型 content 结构不同,详见 content 结构说明 |
mentions | array | 被@的用户信息 |
∟ company_uid | string | 被@的用户 id |
∟ company_id | string | 被@的用户所属的企业 id |
事件体示例(解密后)
data: {
"chat_id": 12345, // 会话id
"chat_type": 2, // 会话类型:2-群聊,3-单聊
"company_id": "string", // 企业id
"sender": {
"company_uid": "string", // 发送者的用户id
"company_id": "string" // 发送者所属的企业id
},
"send_time": 0, // 发送时间
"message_id": 22331, // 消息id
"message_type": 10, // 消息类型:0-文本、7-回复、12-文件、13-表情或图片、18-图文混排
"content": { // 不同消息类型content结构不同,此处仅为示例
"type": "plainText", // plainText - 普通文本,markdown - markdown文本
"text": "xxx"
},
"mentions": [
{
"company_uid": "string", // 被@的用户id
"company_id": "string", // 被@的用户所属的企业id
}
]
}
参数结构说明(Content)
文本(type=0)
{
"type": "plainText", // plainText - 普通文本,markdown - markdown文本
"text": "xxx"
}
回复(type=7)
{
"ref_msg_id": 12345, // 被引用消息id
"ref_content_type": 7, // 被引用消息内容的格式
"ref_content": {}, // 被引用消息内容,格式参考其余消息类型即可(文本、图文混排、表情包)
"content_type": 7,
"content": {} // 回复的内容,格式参考其余消息类型(文本、图文混排、表情包)
}
文件(type=12)
{
"store_key": "xxx", // 文件id
"file_name": "xxx" // 文件名
}
表情包和图片(type=13)
{
"store_key": "xxxx", // 图片文件id
"category": "emoji" // 分类 image-图片 emoji-表情
}
图文混排(type=18)
{
"elements": [
{
"tag": "text", // 内容分类 text-文本 emoji-表情 img-图片
"content": {
"text": "awao",
"type": "plainText" // 文本渲染格式 plainText普通文本
}
},
{
"tag": "emoji",
"content": {
"store_key": "DD1AFB29cGljLzBiN2ExZDdhNjIzMWRjYmU0YmNiNzJjMDBmM2JmZjQ1OmtzMzprb2EtaW1n" // 表情文件id
}
},
{
"tag": "img",
"content": {
"store_key": "DD1AFB29Mzg3NDg3Yzk1ZjQzZTFiNWMxYjk2MDhjNjY3ZThhZjk6a3MzOmtvYS1pbWc=" // 图片文件id
}
}
]
}