WeCom Message Sending
Before executing any
command, you must first read and complete the public pre-checks of the
skill.
- 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
- Applicable for sending messages to the authorized user: Use
wecom-cli identity whoami
to obtain the authorized user ID, which can be used as without calling .
- 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
- 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
Skill Dependencies
Before calling dependent skills, you must fully read the corresponding
.
| 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 , you must first read this skill to obtain . The passed during upload must align with the used during sending |
Get the List of Sessions Where Messages Can Be Sent
Command
bash
wecom-cli message aibot sessions list
Return Value
| 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 | for one-on-one chat or for group chat |
| string | Time of the last message, format |
| integer | Number of elements in the array |
Source of
When sending messages to users other than the authorized user, before calling
wecom-cli message aibot send
, you need to call
first, then select the target item from the
returned this time, and copy the
of that item to
as is.
The following values cannot be directly used as
:
- ID entered by the user
- saved in previous rounds or historical context
- returned by
- 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
.
Target Session Matching
- Chat Name: Exact match by non-empty in this ; if exact match is not possible, ask the user to confirm the sending target. Copy from the matching item when there is a unique hit.
- First Recent/Recent Session: Select the item explicitly specified by the user according to the original order of .
- User-provided ID: Only perform exact equality check with this ; after hitting, still copy from the matching item, do not directly reuse the user-input value.
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.
- 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.
- Stop sending when , and inform the user that there are no recent sessions available for sending.
- Keep the original order of the interface when displaying the session list; display the name and time, do not show the internal .
Send Messages
Preconditions
Before calling this interface, you must complete the following steps:
- Choose to call
wecom-cli message aibot sessions list
to obtain or wecom-cli identity whoami
to obtain the authorized user ID according to the recipient.
- 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.
- Prepare the corresponding when sending media messages.
Do not upload media or call
before the target session is successfully matched.
Command
bash
wecom-cli message aibot send --json '<JSON Parameters>'
Public Parameters
| Field | Type | Required | Description |
|---|
| string | Yes | Must be obtained from wecom-cli identity whoami
or the target returned by the just called in the current sending process |
| 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.
Markdown Messages
is required, with a maximum length of 20480 UTF-8 bytes. Plain text is also sent as Markdown.
bash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "markdown",
"markdown": {
"content": "<Markdown Message Content>"
}
}'
Image Messages
is required, which must be obtained by uploading via the media upload interface with
.
bash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "image",
"image": {
"media_id": "<media_id>"
}
}'
File Messages
is required, which must be obtained by uploading via the media upload interface with
; the file name is the original file name used during upload.
bash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "file",
"file": {
"media_id": "<media_id>"
}
}'
Voice Messages
is required, which must be obtained by uploading via the media upload interface with
; the source file only supports AMR format, and you cannot pretend it is AMR by only changing the file extension.
bash
wecom-cli message aibot send --json '{
"chat_id": "<Current sessions[].chat_id>",
"msg_type": "voice",
"voice": {
"media_id": "<media_id>"
}
}'
Video Messages
| 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
- 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
wecom-cli identity whoami
before each , but re-call to ensure the correctness of when the context is compressed during continuous sending.
- , , and are internal call values, and it is forbidden to display them to users.
- 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.