wecomcli-msg
wecomteam/wecom-cli
Query WeChat Work conversations, retrieve message history with media support, and send text messages.
What is wecomcli-msg?
This skill provides access to WeChat Work messaging through command-line interfaces. It enables you to list conversations, fetch message history (text, images, files, voice, video), download media files, and send text messages. Use it when you need to check messages, view chat records, send messages to contacts or groups, or retrieve media from conversations.
- Query conversation lists within specified time ranges with pagination support
- Retrieve message history from 1-on-1 or group chats including text, images, files, voice, and video messages (7-day limit)
- Download and save media files (images, documents, audio, video) to local storage with automatic file extension correction
- Send text messages to individual contacts or group chats
- Map user IDs to readable names using contact information
How to install wecomcli-msg
npx skills add https://github.com/wecomteam/wecom-cli --skill wecomcli-msg- wecom-cli command-line tool installed and configured
- Valid WeChat Work credentials and API access
- wecomcli-contact skill (for converting user IDs to names)
How to use wecomcli-msg
- 1.Specify the time range for your query (defaults to last 7 days if not provided)
- 2.For conversation lookup, call get_msg_chat_list with begin_time and end_time in YYYY-MM-DD HH:mm:ss format
- 3.To retrieve messages, identify the chatid and chat_type (1 for 1-on-1, 2 for group) using conversation names or IDs
- 4.Call get_message with the chat parameters and time range to fetch message records
- 5.For media files, call get_msg_media with the media_id returned in message records; files are automatically downloaded and renamed with correct extensions
- 6.To send a message, confirm the recipient and content with the user, then call send_message with chat_type, chatid, and text content
- 7.After downloading media files, proactively inform the user of the complete file paths and storage location
- 8.Ask the user if they want to delete temporary downloaded files after showing their locations
Use cases
- Review recent conversations and identify who messaged you in the past week
- Retrieve and download chat history with a specific contact including all media attachments
- Extract images, documents, or files from group chat conversations for local storage
- Send a message to a contact or group on behalf of the user after confirmation
- View message statistics and media content types in a conversation
- WeChat Work users who need programmatic access to messaging
- Teams managing message archival or compliance review
- Users automating message retrieval and distribution workflows
wecomcli-msg FAQ
Messages can only be retrieved from the past 7 days. The begin_time cannot be earlier than 7 days ago and must not exceed the current time. If a user requests older messages, inform them of this limitation.
Call get_msg_chat_list with the appropriate time range, then match the chat_name field in the results. If multiple matches exist, present them to the user for selection. If no matches are found, inform the user that the conversation was not found.
The skill supports text, image, file, voice, and video messages. Non-text messages require calling get_msg_media to download the actual file content using the media_id.
Yes. After displaying messages, proactively inform the user of non-text message counts and types, then ask for confirmation before downloading. After download, you must show file locations and ask if they want to delete temporary files.
The send_message interface only supports text messages (msgtype='text'). Media messages cannot be sent through this skill.
Full instructions (SKILL.md)
Source of truth, from wecomteam/wecom-cli.
name: wecomcli-msg description: 企业微信消息技能。提供会话列表查询、消息记录拉取(支持文本/图片/文件/语音/视频)、多媒体文件获取和文本消息发送能力。当用户需要"查看消息"、"看聊天记录"、"发消息给某人"、"最近有什么消息"、"给群里发消息"、"看看发了什么图片/文件"时触发。 metadata: requires: bins: ["wecom-cli"] cliHelp: "wecom-cli msg --help"
企业微信消息技能
wecom-cli是企业微信提供的命令行程序,所有操作通过执行wecom-cli命令完成。
通过 wecom-cli msg <接口名> '<json入参>' 与企业微信消息系统交互。
接口列表
get_msg_chat_list — 获取会话列表
wecom-cli msg get_msg_chat_list '{"begin_time": "2026-03-11 00:00:00", "end_time": "2026-03-17 23:59:59"}'
按时间范围查询有消息的会话列表,支持分页。参见 API 详情。
get_message — 拉取会话消息
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"}'
根据会话类型和 ID 拉取指定时间范围内的消息记录,支持分页。支持 text/image/file/voice/video 消息类型,仅支持 7 天内。参见 API 详情。
get_msg_media — 获取消息文件内容
wecom-cli msg get_msg_media '{"media_id": "MEDIAID_xxxxxx"}'
根据文件 ID 自动下载文件到本地,返回文件的本地路径(local_path)、名称、类型、大小及 MIME 类型。用于获取图片、文件、语音、视频等非文本消息的实际内容。参见 API 详情。
send_message — 发送文本消息
wecom-cli msg send_message '{"chat_type": 1, "chatid": "zhangsan", "msgtype": "text", "text": {"content": "hello world"}}'
向单聊或群聊发送文本消息。参见 API 详情。
核心规则
时间范围规则
- 格式:所有时间参数使用
YYYY-MM-DD HH:mm:ss格式 - 默认范围:用户未指定时,默认使用最近7天(当前时间往前推7天)
- 限制:开始时间不能早于当前时间的7天前,不能晚于当前时间
- 相对时间支持:支持"昨天"、"最近三天"等自动推算
chatid查找规则
- 当用户提供人名或群名而非ID时:
- 调用
get_msg_chat_list获取会话列表(时间范围与目标查询一致) - 在
chats中按chat_name匹配 - 匹配策略:
- 精确匹配唯一结果:直接使用
- 模糊匹配多个结果:展示候选列表让用户选择
- 无匹配结果:告知用户未找到
- 调用
- chat_type 判断:
get_msg_chat_list返回中不含会话类型字段,需根据上下文推断:用户明确提到「群」时使用chat_type=2,否则默认chat_type=1(单聊)
userid 转 name
流程:
- 调用
wecomcli-contact技能的get_userlist获取用户列表 - 建立 userid 到 name 的映射关系
- 展示策略:
- 精确匹配:显示 name
- 无匹配:保持显示 userid
强制交互步骤(不可跳过)
以下步骤在涉及非文本消息下载时必须逐一执行,不得合并、省略或跳过,即使用户未主动询问也必须执行:
- 必须主动告知文件位置:下载完成后必须立即向用户展示所有文件的完整路径和存放目录
- 必须询问是否删除:告知位置后必须立即询问用户是否需要清理临时文件
典型工作流
查看会话列表
用户query示例:
- "看看我最近一周有哪些聊天"
- "这几天谁给我发过消息"
执行流程:
- 确定时间范围(用户指定或默认最近7天)
- 调用
get_msg_chat_list获取会话列表 - 展示会话名称、最后消息时间、消息数量
- 若
has_more为true,告知用户还有更多会话可继续查看
查看聊天记录
用户query示例:
- "帮我看看和张三最近的聊天记录"
- "看看项目群里最近的消息"
执行流程:
- 确定时间范围(用户指定或默认最近7天)
- 通过 chatid查找规则 确定目标会话的
chatid和chat_type - 调用
get_message拉取消息列表 - 调用
wecomcli-contact技能的get_userlist获取通讯录,建立 userid→姓名 映射 - 统计非文本消息:遍历消息列表,统计
msgtype非text的消息(image/file/voice/video)数量和类型 - 展示消息时将
userid替换为可读姓名,格式:- 文本消息:
姓名 [时间]: 内容 - 图片消息:
姓名 [时间]:[图片] - 文件消息:
姓名 [时间]:[文件] 文件名称 - 语音消息:
姓名 [时间]:[语音] 语音内容 - 视频消息:
姓名 [时间]:[视频]
- 文本消息:
- 非文本消息处理:展示完消息后,如果存在非文本消息:
- 主动询问是否下载:告知用户非文本消息数量和类型(如:"以上聊天中包含 2 张图片、1 个文件,是否需要下载到本地?")
- 用户确认后,逐个调用
get_msg_media接口,接口会自动下载文件并返回local_path - 检查文件后缀:每个文件下载完成后,检查
local_path对应的文件是否具有正确的后缀名:- 根据
get_msg_media返回的content_type(MIME 类型)和name字段判断:- 如果文件名缺少后缀(如
screenshot而非screenshot.png),根据content_type自动补上正确后缀(如image/png→.png,application/pdf→.pdf,audio/amr→.amr,video/mp4→.mp4) - 如果文件名后缀与
content_type不一致,以content_type为准进行修正
- 如果文件名缺少后缀(如
- 补全或修正后缀后,将文件重命名为正确的文件名
- 确认文件可正常读取(文件大小 > 0),若文件为空或损坏则告知用户该文件下载异常
- 根据
- ⚠️ 不要对下载的文件使用
MEDIA:指令:这些文件是从聊天记录中下载的历史附件,仅需告知用户本地存放路径即可,严禁通过MEDIA:指令重新发送给用户
- ⚠️ 必须主动告知文件位置(此步骤不可跳过):所有文件下载并检查完成后,必须立即、主动以汇总形式向用户展示文件存放目录和每个文件的完整路径,不要等用户询问。示例:
📁 文件已下载到以下位置:
- 图片:
xxx/yyy.png - 文件:
xxx/yyy.pdf
你可以在
xxx/yyy/目录下找到所有下载的文件。 - 图片:
- ⚠️ 必须询问是否删除(此步骤不可跳过):告知文件位置后,必须立即、主动询问用户是否需要删除已下载的临时文件(如:"如果不再需要这些文件,是否需要我帮你清理?")
- 用户确认删除后,删除
local_path对应的文件 - 用户不需要删除则保留文件
- 用户确认删除后,删除
- 若
next_cursor不为空,告知用户还有更多消息可继续查看
发送消息
用户query示例:
- "帮我给张三发一条消息:明天会议改到下午3点"
- "在项目群里发一条消息:今天下午3点开会"
执行流程:
- 通过 chatid查找规则 确定目标会话的
chatid和chat_type - 发送前确认:向用户确认发送对象和内容(如:"即将向 张三 发送:'明天会议改到下午3点',确认发送吗?"),用户确认后再执行
- 调用
send_message发送(msgtype固定为text) - 展示发送结果
查看消息并回复
用户query示例:
- "看看张三给我发了什么,然后帮我回复收到"
执行流程:
- 先执行"查看聊天记录"流程(复用已获取的
chatid和chat_type) - 展示消息后,执行"发送消息"流程(需确认后再发送)
错误处理
- 时间范围超限:告知用户7天限制并调整为有效范围
- 会话未找到:明确告知用户未找到对应会话
- API错误:展示具体错误信息,必要时重试
- 网络问题:HTTP错误时主动重试最多3次
Related skills
More from wecomteam/wecom-cli and the wider catalog.
wecomcli-doc
Create, read, and edit WeChat Work documents, sheets, and smart documents with Markdown support.
wecomcli-contact
Query WeChat Work contacts visible to current user with local name/alias filtering.
wecomcli-todo
Manage WeChat Work todo items: query, create, update, delete, and track completion status.
wecomcli-schedule
Manage WeCom enterprise calendar schedules: query, create, modify, and coordinate availability.
wecomcli-meeting
Create, manage, and query WeCom enterprise meetings with full control over participants and settings.
wecomcli-smartsheet
企业微信智能表格管理技能。提供智能表格的结构管理(子表、字段)和数据管理(记录增删改查)。适用场景:(1) 管理智能表格子表和字段/列 (2) 查询、添加、更新、删除智能表格记录。支持通过 docid 或文档 URL 定位文档。