juhecli-msg 企微消息
juhecli-msg — 企微消息管理:发送文本/图片/文件/链接/语音/位置消息、群@消息、撤回、确认已读
使用案例
账号 Hanson 发送生日祝福给客户 Jony撤回刚才那条消息在技术部群@所有人明天开会给张三发个文件报告.pdf
给张三发消息hello
搜索联系人并发送文本消息
>给张三发消息hello
// Agent 先搜索联系人获取 user_id
$juhe-cli contact search --keyword 张三
{
"data": {
"list": [
{
"user_id": "xxxx-xxxx-xxxx",
"nickname": "张三",
"department": "技术部"
}
]
}
}
// Agent 构建会话ID并发送消息
$juhe-cli msg send_text --conversation_id S:xxxx-xxxx-xxxx --content hello
{
"data": {
"msgid": "msg-xxxx-xxxx-xxxx",
"status": "sent"
}
}
在群里@所有人
在群聊中发送@所有人消息
>在技术部群@所有人明天开会
// Agent 先查找技术部群的 room_id
$juhe-cli room list
{
"data": {
"list": [
{
"room_id": "rrrr-rrrr-rrrr",
"room_name": "技术部",
"member_count": 12
}
]
}
}
// Agent 发送群@消息,at_list 使用 @all
$juhe-cli msg send_room_at --conversation_id R:rrrr-rrrr-rrrr --content 明天开会 --at_list @all
{
"data": {
"msgid": "msg-yyyy-yyyy-yyyy",
"status": "sent"
}
}
概述
企微消息 SKILL 提供全面的企业微信消息发送和管理功能,支持多种消息类型: 文本、图片、文件、链接、语音、位置和群@消息。同时支持消息撤回和已读确认。
conversation_id 格式
所有消息命令都需要
conversation_id 参数。私聊使用 S:user_id 格式, 群聊使用 R:room_id 格式。Agent 会自动通过搜索联系人或群组获取对应 ID 并组装。触发方式
用户可能会这样自然地表达需求:
- "给张三发消息hello"
- "发送图片给李四"
- "撤回消息"
- "在群里@张三"
- "给技术部群发个文件"
- "把这篇文章发给王五"
命令列表
| SKILL 名称 | 说明 |
|---|---|
juhecli-msg | 企微消息管理 - 发送文本/图片/文件/链接/语音/位置消息,群@消息,撤回,确认已读 |
详细命令说明
发送文本消息 (msg send_text)
向指定对话发送文本消息。是最常用的消息发送命令。用户只需告诉 Agent 发给谁、发什么内容。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
conversation_id | string | 是 | [需查询] | 对话 ID,私聊 S:user_id,群聊 R:room_id |
content | string | 是 | [用户提供] | 用户提供的消息文本内容 |
返回值
msgid— 消息 ID,Agent 保存此值以备撤回时使用- 发送状态
发送图片消息 (msg send_image)
向指定对话发送图片。需要先通过上传接口获取 file_id 等参数。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
conversation_id | string | 是 | [需查询] | 对话 ID |
file_id | string | 是 | [需上传获取] | 上传后返回的文件 ID |
aes_key | string | 是 | [需上传获取] | 加密密钥 |
md5 | string | 是 | [需上传获取] | 文件 MD5 校验值 |
size | number | 是 | [需上传获取] | 文件大小(字节) |
image_width | number | 是 | [需上传获取] | 图片宽度 |
image_height | number | 是 | [需上传获取] | 图片高度 |
is_hd | boolean | 否 | [需上传获取] | 是否高清图 |
发送文件消息 (msg send_file)
向指定对话发送文件。与图片类似,需要先上传获取文件参数。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
conversation_id | string | 是 | [需查询] | 对话 ID |
file_id | string | 是 | [需上传获取] | 上传后返回的文件 ID |
file_name | string | 是 | [用户提供] | 用户提供的文件名(含扩展名) |
aes_key | string | 是 | [需上传获取] | 加密密钥 |
md5 | string | 是 | [需上传获取] | 文件 MD5 校验值 |
size | number | 是 | [需上传获取] | 文件大小(字节) |
发送链接消息 (msg send_link)
向指定对话发送链接卡片消息。用户提供链接标题、描述和地址。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
conversation_id | string | 是 | [需查询] | 对话 ID |
title | string | 是 | [用户提供] | 用户提供的链接标题 |
description | string | 否 | [用户提供] | 用户提供的链接描述 |
url | string | 是 | [用户提供] | 用户提供的链接地址 |
image_url | string | 否 | [用户提供] | 用户提供的封面图片 URL |
发送位置消息 (msg send_location)
向指定对话发送位置信息。用户提供位置名称、地址和经纬度。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
conversation_id | string | 是 | [需查询] | 对话 ID |
title | string | 是 | [用户提供] | 用户提供的位置名称 |
address | string | 是 | [用户提供] | 用户提供的详细地址 |
latitude | number | 是 | [用户提供] | 用户提供的纬度 |
longitude | number | 是 | [用户提供] | 用户提供的经度 |
zoom | number | 否 | [用户提供] | 用户提供的缩放级别 |
发送语音消息 (msg send_voice)
向指定对话发送语音消息。语音文件需先上传获取参数。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
conversation_id | string | 是 | [需查询] | 对话 ID |
file_id | string | 是 | [需上传获取] | 上传后返回的文件 ID |
aes_key | string | 是 | [需上传获取] | 加密密钥 |
md5 | string | 是 | [需上传获取] | 文件 MD5 |
size | number | 是 | [需上传获取] | 文件大小 |
voice_time | number | 是 | [需上传获取] | 语音时长(秒) |
发送群@消息 (msg send_room_at)
向群聊发送@消息,可@特定成员或所有人。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
conversation_id | string | 是 | [需查询] | 群聊 ID,格式 R:room_id |
content | string | 是 | [用户提供] | 用户提供的消息内容 |
at_list | array | 是 | [需查询] | Agent 通过群成员列表获取用户 ID,@all 表示@所有人 |
撤回消息 (msg revoke)
撤回已发送的消息。需使用发送消息时返回的 msgid。Agent 应自动保存每次发送消息的 msgid。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
conversation_id | string | 是 | [需查询] | 对话 ID |
msgid | string | 是 | [来自发送返回值] | Agent 从发送消息时的返回值中获取 |
撤回时限
消息撤回有时间限制(通常为 2 分钟),超过时间后无法撤回。 AI Agent 应在发送消息后保存 msgid,以便用户需要时撤回。
确认已读 (msg confirm)
标记消息为已读状态。
参数
| 参数 | 类型 | 必填 | 来源 | 说明 |
|---|---|---|---|---|
sender | string | 是 | [需查询] | 发送者 ID |
receiver | string | 是 | [需查询] | 接收者 ID |
roomid | string | 否 | [需查询] | 群 ID |
msgid | string | 是 | [来自消息回调] | 消息 ID |
message_type | number | 是 | [需查询] | 消息类型 |
参数来源说明
| 参数 | 来源标记 | 获取方式 |
|---|---|---|
guid | [需查询] | Agent 通过 device list 获取 |
conversation_id | [需查询] | Agent 自动构建:私聊 S: + contact search 返回的 user_id;群聊 R: + room list 返回的 room_id |
content | [用户提供] | 用户直接提供消息内容 |
file_id / aes_key / md5 / size | [需上传获取] | Agent 通过文件上传接口获取 |
file_name | [用户提供] | 用户直接提供文件名 |
title / url / description / image_url | [用户提供] | 用户直接提供链接信息 |
msgid | [来自发送返回值] | Agent 自动保存发送消息后返回的消息 ID |
at_list | [需查询] | Agent 通过群成员列表获取用户 ID,或使用 @all |
Agent 交互示例
发送文本消息
text
用户: "给张三发消息:明天开会"
AI: 好的,先搜索张三的联系方式...
[Agent 调用 contact search,keyword: "张三"]
找到张三 (user_id: zhangsan)
[Agent 调用 msg send_text,conversation_id: "S:zhangsan", content: "明天开会"]
消息已发送给张三!发送文件
text
用户: "把报告.pdf发给技术部群"
AI: 好的,正在处理...
[Agent 上传文件,获取 file_id、aes_key、md5、size]
[Agent 查找技术部群的 room_id]
[Agent 调用 msg send_file,conversation_id: "R:room123", file_name: "报告.pdf", ...]
文件"报告.pdf"已发送到技术部群!发送群@消息
text
用户: "在技术部群@所有人:明天10点开会"
AI: 好的,正在发送...
[Agent 查找技术部群的 room_id 和群成员信息]
[Agent 调用 msg send_room_at,conversation_id: "R:room123", content: "明天10点开会", at_list: ["@all"]]
群@消息已发送到技术部群!撤回消息
text
用户: "撤回刚才那条消息"
AI: [Agent 使用发送时保存的 msgid]
[Agent 调用 msg revoke,conversation_id: "S:zhangsan", msgid: "msg_001"]
消息已撤回。典型工作流
搜索联系人后发送文本
- 用户说"给张三发消息:明天开会"
- Agent 调用
contact search查找张三,获取 user_id - Agent 构建 conversation_id(
S:user_id) - Agent 调用
msg send_text发送消息 - Agent 保存返回的 msgid 以备撤回
- Agent 向用户确认消息已发送
text
// 完整工作流示例
用户: "给张三发消息hello"
AI: [Agent 调用 contact search,keyword: "张三"]
找到张三 (user_id: zhangsan)
[Agent 调用 msg send_text,conversation_id: "S:zhangsan", content: "hello"]
消息已发送给张三!(msgid: msg_001,如需撤回请告诉我)发送图片/文件
- 用户说"把这张图片发给技术部群"
- Agent 上传文件获取 file_id 等参数
- Agent 查找技术部群的 room_id
- Agent 调用
msg send_image或msg send_file发送
撤回消息
- 用户说"撤回刚才那条消息"
- Agent 使用发送时保存的 msgid
- Agent 调用
msg revoke撤回 - 如超过时限,告知用户无法撤回
错误处理
| 错误 | 原因 | 处理方式 |
|---|---|---|
| conversation_id 无效 | ID 格式错误或不存在 | 检查 S: / R: 前缀,重新查询联系人/群组 |
| file_id 无效 | 文件未上传或已过期 | 重新上传文件获取参数 |
| 撤回超时 | 超过 2 分钟撤回时限 | 告知用户消息已无法撤回 |
| 权限不足 | 非群成员发群消息 | 确认用户是否为群成员 |
| 频率限制 | 短时间内发送过多消息 | 降低发送频率,增加间隔 |
发送频率
避免短时间内发送大量消息,可能触发平台限流。 AI Agent 应在批量发送时控制频率,建议每条消息间隔 1-2 秒。