wecomcli-message

Original🇨🇳 Chinese
Translated

Query the scope of chat sessions where messages can be sent currently, and send text, Markdown, image, file, voice, and video messages to one-on-one chats or group chats in the session list. Use this when the user requests "send a message to someone", "notify in a certain group", "send a message to recent sessions", or "send images/files/voice/video to WeCom".

11installs
Added on

NPX Install

npx skill4agent add wecomteam/wecom-cli wecomcli-message

Tags

Translated version includes tags in frontmatter

SKILL.md Content (Chinese)

View Translation Comparison →

WeCom Message Sending

Before executing any
wecom-cli
command, you must first read and complete the public pre-checks of the
wecomcli-shared
skill.
  1. You can send messages to the authorized user.
  2. 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
    chat_id
    without calling
    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

  • The recipient is not the authorized user and not in the result returned by this
    sessions list
    → 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
SKILL.md
.
Dependent SkillTrigger ScenarioData Flow
wecomcli-media
When sending images, files, voice or videos, only the local file path is available and there is no reusable
media_id
Includes media upload interfaces. If there is no existing
media_id
, you must first read this skill to obtain
media_id
. The
type
passed during upload must align with the
msg_type
used during sending

Get the List of Sessions Where Messages Can Be Sent

Command

bash
wecom-cli message aibot sessions list

Return Value

FieldTypeDescription
sessions
arraySession list, sorted by the time of the last message from newest to oldest. The specific quantity is subject to the actual response
sessions[].chat_id
stringSession ID
sessions[].chat_name
stringGroup name or one-on-one chat name
sessions[].chat_type
string
single
for one-on-one chat or
group
for group chat
sessions[].last_msg_time
stringTime of the last message, format
YYYY-MM-DD HH:MM:SS
sessions_count
integerNumber of elements in the
sessions
array

Source of
chat_id

When sending messages to users other than the authorized user, before calling
wecom-cli message aibot send
, you need to call
sessions list
first, then select the target item from the
sessions[]
returned this time, and copy the
chat_id
of that item to
send.chat_id
as is.
The following values cannot be directly used as
send.chat_id
:
  • ID entered by the user
  • chat_id
    saved in previous rounds or historical context
  • userid
    returned by
    wecomcli-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

  • Chat Name: Exact match by non-empty
    chat_name
    in this
    sessions[]
    ; if exact match is not possible, ask the user to confirm the sending target. Copy
    chat_id
    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
    sessions[]
    .
  • User-provided ID: Only perform exact equality check with this
    sessions[].chat_id
    ; after hitting, still copy
    chat_id
    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
    sessions list
    , 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
    chat_id
    to bypass restrictions.
  • Stop sending when
    sessions_count=0
    , 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
    chat_id
    .

Send Messages

Preconditions

Before calling this interface, you must complete the following steps:
  1. Choose to call
    wecom-cli message aibot sessions list
    to obtain
    chat_id
    or
    wecom-cli identity whoami
    to obtain the authorized user ID according to the recipient.
  2. Uniquely match the target in this list.
  3. If sending to an object other than the authorized user, copy
    sessions[].chat_id
    from the matching item in the list as is.
  4. Prepare the corresponding
    media_id
    when sending media messages.
Do not upload media or call
send
before the target session is successfully matched.

Command

bash
wecom-cli message aibot send --json '<JSON Parameters>'

Public Parameters

FieldTypeRequiredDescription
chat_id
stringYesMust be obtained from
wecom-cli identity whoami
or the target
sessions[].chat_id
returned by the
sessions list
just called in the current sending process
msg_type
stringYes
markdown
/
image
/
file
/
voice
/
video
markdown
objectConditionally RequiredOnly pass when
msg_type="markdown"
image
objectConditionally RequiredOnly pass when
msg_type="image"
file
objectConditionally RequiredOnly pass when
msg_type="file"
voice
objectConditionally RequiredOnly pass when
msg_type="voice"
video
objectConditionally RequiredOnly pass when
msg_type="video"
Each request must carry exactly one content object with the same name as
msg_type
. Do not pass empty objects, and do not pass multiple message objects at the same time.

Markdown Messages

markdown.content
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

image.media_id
is required, which must be obtained by uploading via the media upload interface with
type=image
.
bash
wecom-cli message aibot send --json '{
  "chat_id": "<Current sessions[].chat_id>",
  "msg_type": "image",
  "image": {
    "media_id": "<media_id>"
  }
}'

File Messages

file.media_id
is required, which must be obtained by uploading via the media upload interface with
type=file
; 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

voice.media_id
is required, which must be obtained by uploading via the media upload interface with
type=voice
; 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

FieldRequiredDescription
video.media_id
YesObtained by uploading via the media upload interface with
type=video
video.title
NoMaximum length of 128 UTF-8 bytes; if omitted, the original file name used during upload is used
video.description
NoMaximum 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
    sessions list
    or
    wecom-cli identity whoami
    before each
    send
    , but re-call to ensure the correctness of
    chat_id
    when the context is compressed during continuous sending.
  • chat_id
    ,
    userid
    , and
    media_id
    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
    wecom-cli
    using curl / Python or other methods.