
wecomcli-msg
PopularWeChat Work message skill. Provides session list query, message history retrieval (supporting text/image/file/voice/video), multimedia file download, and text message sending. Triggered when users need to 'view messages', 'check chat history', 'send a message to someone', 'see recent messages', 'send a message to a group', or 'view images/files sent'.
Related Skills
企业微信消息技能。提供会话列表查询、消息记录拉取(支持文本/图片/文件/语音/视频)、多媒体文件获取和文本消息发送能力。当用户需要"查看消息"、"看聊天记录"、"发消息给某人"、"最近有什么消息"、"给群里发消息"、"看看发了什么图片/文件"时触发。
WeChat Work Message Skill
wecom-cliis the command-line program provided by WeChat Work. All operations are performed by executing thewecom-clicommand.
Interact with the WeChat Work message system via wecom-cli msg <接口名> '<json入参>'.
API List
get_msg_chat_list — Get session list
wecom-cli msg get_msg_chat_list '{"begin_time": "2026-03-11 00:00:00", "end_time": "2026-03-17 23:59:59"}'
Query the list of sessions with messages within a time range, supports pagination. See API details.
get_message — Retrieve session messages
wecom-cli msg get_message '{"chat_type": 1, "chatid": "zhangsan", "begin_time": "2026-03-17 09:00:00", "end_time": "2026-03-17 18:00:00"}'
Retrieve message records within a specified time range based on session type and ID, supports pagination. Supports text/image/file/voice/video message types, only within the last 7 days. See API details.
get_msg_media — Get message file content
wecom-cli msg get_msg_media '{"media_id": "MEDIAID_xxxxxx"}'
Automatically download a file to local based on file ID, returning the local path (local_path), name, type, size, and MIME type. Used to retrieve actual content of non-text messages such as images, files, voice, and video. See API details.
send_message — Send text message
wecom-cli msg send_message '{"chat_type": 1, "chatid": "zhangsan", "msgtype": "text", "text": {"content": "hello world"}}'
Send a text message to a single chat or group chat. See API details.
Core Rules
Time Range Rules
- Format: All time parameters use
YYYY-MM-DD HH:mm:ssformat - Default Range: If not specified by the user, default to the last 7 days (current time minus 7 days)
- Limitation: Start time cannot be earlier than 7 days before current time, and cannot be later than current time
- Relative Time Support: Supports automatic calculation for "yesterday", "last three days", etc.
chatid Lookup Rules
- When the user provides a person or group name instead of an ID:
- Call
get_msg_chat_listto get the session list (time range consistent with the target query) - Match by
chat_nameinchats - Matching Strategy:
- Exact match with unique result: use directly
- Fuzzy match with multiple results: show candidate list for user selection
- No match: inform the user that no session was found
- Call
- chat_type Determination:
get_msg_chat_listresponse does not include a session type field; infer from context: usechat_type=2when the user explicitly mentions "group", otherwise default tochat_type=1(single chat)
userid to Name Mapping
Process:
- Call the
get_userlistAPI of thewecomcli-contactskill to get the user list - Build a mapping from userid to name
- Display Strategy:
- Exact match: show name
- No match: keep showing userid
Mandatory Interaction Steps (Cannot Be Skipped)
The following steps must be performed one by one when downloading non-text messages, and cannot be combined, omitted, or skipped, even if the user does not ask:
- Must proactively inform file location: After download completes, immediately show the user all file paths and the storage directory
- Must ask whether to delete: After informing the location, immediately ask the user if they need to clean up the temporary files
Typical Workflows
View Session List
User query examples:
- "Show me my chats from the past week"
- "Who sent me messages recently"
Execution flow:
- Determine the time range (user-specified or default last 7 days)
- Call
get_msg_chat_listto get the session list - Display session name, last message time, and message count
- If
has_moreistrue, inform the user that more sessions are available
View Chat History
User query examples:
- "Show me the recent chat history with Zhang San"
- "Check the recent messages in the project group"
Execution flow:
- Determine the time range (user-specified or default last 7 days)
- Use chatid lookup rules to determine the target session's
chatidandchat_type - Call
get_messageto retrieve the message list - Call the
get_userlistAPI of thewecomcli-contactskill to get the address book and build userid→name mapping - Count non-text messages: Iterate through the message list, count the number and types of messages where
msgtypeis nottext(image/file/voice/video) - When displaying messages, replace
useridwith readable names, format:- Text message:
姓名 [时间]: 内容 - Image message:
姓名 [时间]:[图片] - File message:
姓名 [时间]:[文件] 文件名称 - Voice message:
姓名 [时间]:[语音] 语音内容 - Video message:
姓名 [时间]:[视频]
- Text message:
- Non-text message handling: After displaying messages, if there are non-text messages:
- Proactively ask whether to download: Inform the user of the count and types of non-text messages (e.g., "The chat above contains 2 images and 1 file. Would you like to download them locally?")
- After user confirmation, call
get_msg_mediafor each file; the API automatically downloads the file and returnslocal_path - Check file extension: After each file download, check if the file at
local_pathhas the correct extension:- Based on the
content_type(MIME type) andnamefields returned byget_msg_media:- If the filename lacks an extension (e.g.,
screenshotinstead ofscreenshot.png), automatically append the correct extension based oncontent_type(e.g.,image/png→.png,application/pdf→.pdf,audio/amr→.amr,video/mp4→.mp4) - If the filename extension does not match
content_type, correct it based oncontent_type
- If the filename lacks an extension (e.g.,
- After appending or correcting the extension, rename the file to the correct filename
- Confirm the file is readable (file size > 0); if the file is empty or corrupted, inform the user that the download was abnormal
- Based on the
- ⚠️ Do not use the
MEDIA:directive for downloaded files: These files are historical attachments downloaded from chat records; only inform the user of the local storage path, do not resend them via theMEDIA:directive
- ⚠️ Must proactively inform file location (this step cannot be skipped): After all files are downloaded and checked, immediately and proactively show the user the storage directory and the full path of each file in a summary format, without waiting for the user to ask. Example:
📁 Files have been downloaded to the following locations:
- Image:
xxx/yyy.png - File:
xxx/yyy.pdf
You can find all downloaded files in the
xxx/yyy/directory. - Image:
- ⚠️ Must ask whether to delete (this step cannot be skipped): After informing the file location, immediately and proactively ask the user if they want to delete the downloaded temporary files (e.g., "If you no longer need these files, would you like me to clean them up?")
- If the user confirms deletion, delete the files corresponding to
local_path - If the user does not want to delete, keep the files
- If the user confirms deletion, delete the files corresponding to
- If
next_cursoris not empty, inform the user that more messages are available
Send Message
User query examples:
- "Send a message to Zhang San: tomorrow's meeting is moved to 3 PM"
- "Send a message in the project group: meeting at 3 PM today"
Execution flow:
- Use chatid lookup rules to determine the target session's
chatidandchat_type - Confirm before sending: Ask the user to confirm the recipient and content (e.g., "About to send to Zhang San: 'tomorrow's meeting is moved to 3 PM'. Confirm sending?"), then send after user confirmation
- Call
send_messageto send (msgtypeis fixed totext) - Display the send result
View Messages and Reply
User query examples:
- "Check what Zhang San sent me, then reply 'received'"
Execution flow:
- First execute the "View Chat History" flow (reuse the already obtained
chatidandchat_type) - After displaying messages, execute the "Send Message" flow (requires confirmation before sending)
Error Handling
- Time range exceeded: Inform the user of the 7-day limit and adjust to a valid range
- Session not found: Clearly inform the user that the session was not found
- API error: Display specific error information, retry if necessary
- Network issues: On HTTP errors, automatically retry up to 3 times





