目录
当用户与智能机器人进行交互时,企业微信会将相关的交互事件回调到开发者设置的回调URL,开发者可根据事件类型做出相应的响应,实现丰富的自定义功能。
目前主要有以下场景支持回复消息:
具体可参考接收回调与被动回复消息流程
{
"msgtype": "text",
"text": {
"content": "hello\nI'm RobotA\n"
}
}
参数说明:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
| msgtype | String | 是 | 此时固定为text |
| text | Object | 是 | 文本消息的详细内容 |
| text.content | String | 是 | 文本内容 |
目前仅支持进入会话回调事件时,支持被动回复文本消息
{
"msgtype": "template_card",
"template_card": {
"card_type": "multiple_interaction",
"source": {
"icon_url": "https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0",
"desc": "企业微信"
},
"main_title": {
"title": "欢迎使用企业微信",
"desc": "您的好友正在邀请您加入企业微信"
},
"select_list": [
{
"question_key": "question_key_one",
"title": "选择标签1",
"disable": false,
"selected_id": "id_one",
"option_list": [
{
"id": "id_one",
"text": "选择器选项1"
},
{
"id": "id_two",
"text": "选择器选项2"
}
]
},
{
"question_key": "question_key_two",
"title": "选择标签2",
"selected_id": "id_three",
"option_list": [
{
"id": "id_three",
"text": "选择器选项3"
},
{
"id": "id_four",
"text": "选择器选项4"
}
]
}
],
"submit_button": {
"text": "提交",
"key": "submit_key"
},
"task_id": "task_id"
}
}
参数说明:
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
| msgtype | String | 是 | 此时固定为template_card |
| template_card | Object | 是 | 模板卡片TemplateCard结构体。参考模板卡片类型中类型说明参考模板卡片类型中类型说明 |
目前仅支持进入会话回调事件或者接收消息回调时,支持被动回复模板卡片消息
{
"msgtype": "stream",
"stream": {
"id": "STREAMID",
"finish": false,
"content": "**广州**今日天气:29度,大部分多云,降雨概率:60%",
"msg_item": [
{
"msgtype": "image",
"image": {
"base64": "BASE64",
"md5": "MD5"
}
}
]
}
}
参数说明:
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| msgtype | String | 是 | 消息类型,此时固定为:stream |
| stream.id | String | 否,流式消息首次回复的时候要求设置 | 自定义的唯一id,某次回调的首次回复第一次设置,后续回调会根据这个id来获取最新的流式消息 |
| stream.finish | Bool | 否 | 流式消息是否结束 |
| stream.content | String | 否 | 流式消息内容,最长不超过20480个字节,必须是utf8编码。 特殊的,第一次回复内容为"1",第二次回复"123",则此时消息展示内容"123" |
| stream.msg_item | Object[] | 否 | 流式消息图文混排消息列表。 |
| stream.msg_item.msgtype | String | 否 | 图文混排消息类型,目前支持:image 特殊的,目前image的消息类型仅当finish=true,即流式消息结束的最后一次回复中设置 |
| stream.msg_item.image | Object | 否 | 图片混排的图片资源。目前最多支持设置10个 |
| image.base64 | String | 是 | 图片内容的base64编码。 图片(base64编码前)最大不能超过10M,支持JPG,PNG格式 |
| image.md5 | String | 是 | 图片内容(base64编码前)的md5值 |
流式消息回复内容content字段支持常见的markdown格式
若content中包含思考过程<think></think>标签,客户端会展示思考过程。
若回复内容包含图片,仅支持在最后一次回复时,即finish=true时支持包含msgtype为image的msg_item。
目前仅支持进入会话回调事件或者接收消息回调时,支持被动回复模板卡片消息
{
"msgtype": "template_card",
"template_card": {
}
}
具体参考回复欢迎语中的模板卡片消息说明。
若开发者需要回复流式消息外,还需要回复模板卡片,可回复该消息类型。
首次回复时必须返回stream的id。
template_card可首次回复,也可在收到流式消息刷新事件时回复。但是同一个消息只能回复一次。
{
"msgtype": "stream_with_template_card",
"stream": {
"id": "STREAMID",
"finish": false,
"content": "**广州**今日天气:29度,大部分多云,降雨概率:60%",
"msg_item": [
{
"msgtype": "image",
"image": {
"base64": "BASE64",
"md5": "MD5"
}
}
]
},
"template_card": {
}
}
参数说明:
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| msgtype | String | 是 | 消息类型,此时固定为:stream_with_template_card |
| stream | Object | 是 | 参考流式回复消息说明 |
| template_card | Object | 否 | 模板卡片结构体,参考模板卡片类型中类型说明 |
目前仅支持进入会话回调事件或者接收消息回调时,支持被动回复模板卡片消息
当机器人服务接收到模版卡片事件后,可以在该事件的返回包中添加消息进行即时响应。
{
"response_type": "update_template_card",
"userids": ["USERID1","USERID2"],
"template_card": {
}
}
参数说明
| 参数 | 类型 | 必须 | 说明 |
|---|---|---|---|
| response_type | String | 是 | 响应类型,此处固定为update_template_card - 替换部分用户的模版 |
| userids | String[] | 否 | 表示要替换模版卡片消息的userid列表。若不填,则表示替换当前消息涉及到的所有用户。开发者可以通过模版卡片事件中获取userid |
| template_card | Object | 是 | 要替换的模版卡片TemplateCard结构体。参考模板卡片类型中类型说明 |
注:模板卡片中的task_id需跟回调收到的task_id一致
