wecomcli-message
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese企业微信发送消息
WeCom Message Sending
执行任何命令前,必须先读取并完成wecom-cli技能的公共前置检查。wecomcli-shared
- 可以向授权人发送消息。
- 可以向授权人以外的、机器人最近有消息往来的聊天会话(单聊和群聊)发送消息。
Before executing anycommand, you must first read and complete the public pre-checks of thewecom-cliskill.wecomcli-shared
- You can send messages to the authorized user.
- You can send messages to chat sessions (one-on-one chats and group chats) that the robot has recently exchanged messages with, excluding the authorized user.
适用范围
Scope of Application
适用
Applicable Scenarios
- 适用于给授权人发消息,使用 获取授权人ID,可作为
wecom-cli identity whoami使用,无需调用chat_id。sessions list - 适用于查询当前有权限发送消息的聊天会话范围并给这些范围中的成员或群聊发送 Markdown 消息、图片、文件、AMR 语音或视频
- Applicable for sending messages to the authorized user: Use to obtain the authorized user ID, which can be used as
wecom-cli identity whoamiwithout callingchat_id.sessions list - Applicable for querying the scope of chat sessions where you have permission to send messages, and sending Markdown messages, images, files, AMR voice or videos to members or group chats within these scopes
不适用
Inapplicable Scenarios
- 发送对象不是授权人且不在本次 返回结果中 → 告知用户当前只能向最近活跃的会话或授权人发送
sessions list
- The recipient is not the authorized user and not in the result returned by this → Inform the user that currently messages can only be sent to recent active sessions or the authorized user
sessions list
技能依赖
Skill Dependencies
调用依赖技能前,必须先完整读取对应 。
SKILL.md| 依赖技能 | 触发场景 | 数据流向 |
|---|---|---|
| 发送图片、文件、语音或视频时只有本地文件路径,没有可直接复用的 | 包含媒体上传接口,如没有已有的 |
Before calling dependent skills, you must fully read the corresponding .
SKILL.md| Dependent Skill | Trigger Scenario | Data Flow |
|---|---|---|
| When sending images, files, voice or videos, only the local file path is available and there is no reusable | Includes media upload interfaces. If there is no existing |
获取能发送消息的会话列表
Get the List of Sessions Where Messages Can Be Sent
命令
Command
bash
wecom-cli message aibot sessions listbash
wecom-cli message aibot sessions list返回
Return Value
| 字段 | 类型 | 说明 |
|---|---|---|
| array | 会话列表,按最后一条消息时间从新到旧排序,具体数量以实际回包为准 |
| string | 会话 ID |
| string | 群名称或单聊名称 |
| string | |
| string | 最后一条消息时间,格式 |
| integer | |
| Field | Type | Description |
|---|---|---|
| array | Session list, sorted by the time of the last message from newest to oldest. The specific quantity is subject to the actual response |
| string | Session ID |
| string | Group name or one-on-one chat name |
| string | |
| string | Time of the last message, format |
| integer | Number of elements in the |
chat_id
来源
chat_idSource of chat_id
chat_id向授权人以外的用户发送消息,调用 前,需要先调用一次 ,然后从本次返回的 中选定目标项,把该项的 原样复制到 。
wecom-cli message aibot sendsessions listsessions[]chat_idsend.chat_id以下值都不能直接作为 :
send.chat_id- 用户输入的 ID
- 之前轮次或历史上下文保存的
chat_id - 返回的
wecomcli-contactuserid - 根据姓名、群名或其他字段自行构造的值
这些值最多只能作为匹配线索;最终发送参数必须重新取自本次 的匹配项。
sessions listWhen sending messages to users other than the authorized user, before calling , you need to call first, then select the target item from the returned this time, and copy the of that item to as is.
wecom-cli message aibot sendsessions listsessions[]chat_idsend.chat_idThe following values cannot be directly used as :
send.chat_id- ID entered by the user
- saved in previous rounds or historical context
chat_id - returned by
useridwecomcli-contact - Values constructed by yourself based on names, group names or other fields
These values can only be used as matching clues at most; the final sending parameters must be re-obtained from the matching items of this .
sessions list目标会话匹配
Target Session Matching
- 聊天名称:在本次 中按非空
sessions[]精确匹配;不能精确匹配需要向用户反问确认发送目标,唯一命中时从匹配项复制chat_name。chat_id - 最近第一个/最近某个会话:按 原始顺序选择用户明确指定的项。
sessions[] - 用户提供 ID:只能与本次 做完全相等校验;命中后仍从匹配项复制
sessions[].chat_id,不能直接复用用户输入值。chat_id
匹配结果处理:
- 唯一匹配时继续发送。
- 多个聊天会话候选时,按返回顺序展示聊天名和最后消息时间,让用户选择。
- 用户完成选择后,必须重新调用 ,再用选定对象匹配当次返回值。
sessions list - 无匹配时停止发送,如实告知目标不在最近 10 个会话中;不要接受外部 绕过限制。
chat_id - 时停止发送,告知当前没有可发送的最近会话。
sessions_count=0 - 展示会话列表时保持接口原始顺序;展示名称和时间,不展示内部 。
chat_id
- Chat Name: Exact match by non-empty in this
chat_name; if exact match is not possible, ask the user to confirm the sending target. Copysessions[]from the matching item when there is a unique hit.chat_id - First Recent/Recent Session: Select the item explicitly specified by the user according to the original order of .
sessions[] - User-provided ID: Only perform exact equality check with this ; after hitting, still copy
sessions[].chat_idfrom the matching item, do not directly reuse the user-input value.chat_id
Processing of Matching Results:
- Proceed to send when there is a unique match.
- When there are multiple chat session candidates, display the chat names and last message times in the returned order and let the user choose.
- After the user completes the selection, you must re-call , then match the selected object with the current return value.
sessions list - Stop sending when there is no match, and truthfully inform the user that the target is not in the recent 10 sessions; do not accept external to bypass restrictions.
chat_id - Stop sending when , and inform the user that there are no recent sessions available for sending.
sessions_count=0 - Keep the original order of the interface when displaying the session list; display the name and time, do not show the internal .
chat_id
发送消息
Send Messages
前置条件
Preconditions
调用本接口前必须完成以下步骤:
- 根据发送对象选择调用 获取
wecom-cli message aibot sessions list或chat_id获取授权人ID。wecom-cli identity whoami - 在本次列表中唯一匹配目标。
- 如果发送授权人以外的对象,从列表中匹配项原样复制 。
sessions[].chat_id - 目标是媒体消息时,再准备对应的 。
media_id
在目标会话匹配成功前,不上传媒体,也不调用 。
sendBefore calling this interface, you must complete the following steps:
- Choose to call to obtain
wecom-cli message aibot sessions listorchat_idto obtain the authorized user ID according to the recipient.wecom-cli identity whoami - Uniquely match the target in this list.
- If sending to an object other than the authorized user, copy from the matching item in the list as is.
sessions[].chat_id - Prepare the corresponding when sending media messages.
media_id
Do not upload media or call before the target session is successfully matched.
send命令
Command
bash
wecom-cli message aibot send --json '<JSON 参数>'bash
wecom-cli message aibot send --json '<JSON Parameters>'公共参数
Public Parameters
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| string | 是 | 必须取自 |
| string | 是 | |
| object | 条件必填 | 仅 |
| object | 条件必填 | 仅 |
| object | 条件必填 | 仅 |
| object | 条件必填 | 仅 |
| object | 条件必填 | 仅 |
每次请求必须且只能携带一个与 同名的内容对象。不要传空对象,也不要同时传多个消息对象。
msg_type| Field | Type | Required | Description |
|---|---|---|---|
| string | Yes | Must be obtained from |
| string | Yes | |
| object | Conditionally Required | Only pass when |
| object | Conditionally Required | Only pass when |
| object | Conditionally Required | Only pass when |
| object | Conditionally Required | Only pass when |
| object | Conditionally Required | Only pass when |
Each request must carry exactly one content object with the same name as . Do not pass empty objects, and do not pass multiple message objects at the same time.
msg_typeMarkdown 消息
Markdown Messages
markdown.contentbash
wecom-cli message aibot send --json '{
"chat_id": "<本次 sessions[].chat_id>",
"msg_type": "markdown",
"markdown": {
"content": "<markdown 消息内容>"
}
}'markdown.contentbash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "markdown",
"markdown": {
"content": "<Markdown Message Content>"
}
}'图片消息
Image Messages
image.media_idtype=imagebash
wecom-cli message aibot send --json '{
"chat_id": "<本次 sessions[].chat_id>",
"msg_type": "image",
"image": {
"media_id": "<media_id>"
}
}'image.media_idtype=imagebash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "image",
"image": {
"media_id": "<media_id>"
}
}'文件消息
File Messages
file.media_idtype=filebash
wecom-cli message aibot send --json '{
"chat_id": "<本次 sessions[].chat_id>",
"msg_type": "file",
"file": {
"media_id": "<media_id>"
}
}'file.media_idtype=filebash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "file",
"file": {
"media_id": "<media_id>"
}
}'语音消息
Voice Messages
voice.media_idtype=voicebash
wecom-cli message aibot send --json '{
"chat_id": "<本次 sessions[].chat_id>",
"msg_type": "voice",
"voice": {
"media_id": "<media_id>"
}
}'voice.media_idtype=voicebash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "voice",
"voice": {
"media_id": "<media_id>"
}
}'视频消息
Video Messages
| 字段 | 必填 | 说明 |
|---|---|---|
| 是 | 由媒体上传接口以 |
| 否 | 最长 128 UTF-8 字节;省略时使用上传时的原始文件名 |
| 否 | 最长 512 UTF-8 字节;省略时不展示描述 |
bash
wecom-cli message aibot send --json '{
"chat_id": "<本次 sessions[].chat_id>",
"msg_type": "video",
"video": {
"media_id": "<media_id>",
"title": "产品演示",
"description": "本周版本的核心功能演示"
}
}'用户没有提供视频标题或描述时直接省略对应字段,不传空字符串,也不追问非必填字段。
| Field | Required | Description |
|---|---|---|
| Yes | Obtained by uploading via the media upload interface with |
| No | Maximum length of 128 UTF-8 bytes; if omitted, the original file name used during upload is used |
| No | Maximum length of 512 UTF-8 bytes; if omitted, no description is displayed |
bash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "video",
"video": {
"media_id": "<media_id>",
"title": "Product Demo",
"description": "Core function demo of this week's version"
}
}'When the user does not provide a video title or description, directly omit the corresponding fields, do not pass empty strings, and do not ask about non-required fields.
关键约束
Key Constraints
- 用户明确要求发送且目标与内容完整时直接执行,不重复追问确认;缺少目标、内容或本地文件时只追问缺失项。
- 连续发送多条时,不用每次 前都重新调用
send或sessions list,但连续发送中途上下文发生压缩时重新调用确保wecom-cli identity whoami正确。chat_id - 、
chat_id、userid都是内部调用值,禁止面向用户展示。media_id - Markdown 正文、视频标题和描述限制按 UTF-8 字节数计算;超限时不静默截断,请用户缩短或明确同意拆分。
- 发送成功后只说明目标和消息类型,不编造消息 ID。
- 接口失败时如实转达错误,不使用 curl / Python 等方式绕过 。
wecom-cli
- Execute directly when the user clearly requests to send and the target and content are complete; do not repeatedly ask for confirmation. Only ask for missing items when the target, content or local file is missing.
- When sending multiple messages continuously, you do not need to re-call or
sessions listbefore eachwecom-cli identity whoami, but re-call to ensure the correctness ofsendwhen the context is compressed during continuous sending.chat_id - ,
chat_id, anduseridare internal call values, and it is forbidden to display them to users.media_id - The length limits for Markdown content, video title and description are calculated by UTF-8 bytes; do not silently truncate when exceeding the limit, ask the user to shorten or explicitly agree to split.
- After successful sending, only explain the target and message type, do not fabricate message IDs.
- Truthfully convey errors when the interface fails, do not bypass using curl / Python or other methods.
wecom-cli