wecomcli-get-msg
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese企业微信消息技能
WeCom Message Skill
是企业微信提供的命令行程序,所有操作通过执行wecom-cli命令完成。wecom-cli
通过 与企业微信消息系统交互。
wecom-cli msg <接口名> '<json入参>'is a command-line program provided by WeCom, all operations are completed by executing thewecom-clicommand.wecom-cli
Interact with the WeCom message system via .
wecom-cli msg <interface name> '<json parameter>'接口列表
Interface List
get_msg_chat_list — 获取会话列表
get_msg_chat_list — Get session list
bash
wecom-cli msg get_msg_chat_list '{"begin_time": "2026-03-11 00:00:00", "end_time": "2026-03-17 23:59:59"}'按时间范围查询有消息的会话列表,支持分页。参见 API 详情。
bash
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 by time range, supports pagination. See API Details.
get_message — 拉取会话消息
get_message — Pull session messages
bash
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 详情。
bash
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"}'Pull message records within the specified time range according to session type and ID, supports pagination. Supports text/image/file/voice/video message types, only supports messages within 7 days. See API Details.
get_msg_media — 获取消息文件内容
get_msg_media — Get message file content
bash
wecom-cli msg get_msg_media '{"media_id": "MEDIAID_xxxxxx"}'根据文件 ID 自动下载文件到本地,返回文件的本地路径()、名称、类型、大小及 MIME 类型。用于获取图片、文件、语音、视频等非文本消息的实际内容。参见 API 详情。
local_pathbash
wecom-cli msg get_msg_media '{"media_id": "MEDIAID_xxxxxx"}'Automatically download files to local according to the file ID, return the local path (), name, type, size and MIME type of the file. It is used to obtain the actual content of non-text messages such as pictures, files, voices, videos, etc. See API Details.
local_pathsend_message — 发送文本消息
send_message — Send text message
bash
wecom-cli msg send_message '{"chat_type": 1, "chatid": "zhangsan", "msgtype": "text", "text": {"content": "hello world"}}'向单聊或群聊发送文本消息。参见 API 详情。
bash
wecom-cli msg send_message '{"chat_type": 1, "chatid": "zhangsan", "msgtype": "text", "text": {"content": "hello world"}}'Send text messages to private chats or group chats. See API Details.
核心规则
Core Rules
时间范围规则
Time Range Rules
- 格式:所有时间参数使用 格式
YYYY-MM-DD HH:mm:ss - 默认范围:用户未指定时,默认使用最近7天(当前时间往前推7天)
- 限制:开始时间不能早于当前时间的7天前,不能晚于当前时间
- 相对时间支持:支持"昨天"、"最近三天"等自动推算
- Format: All time parameters use the format
YYYY-MM-DD HH:mm:ss - Default range: When the user does not specify, the last 7 days (counting backward from the current time) are used by default
- Limit: The start time cannot be earlier than 7 days before the current time, and cannot be later than the current time
- Relative time support: Supports automatic calculation for "yesterday", "last three days", etc.
chatid查找规则
chatid Search Rules
- 当用户提供人名或群名而非ID时:
- 调用 获取会话列表(时间范围与目标查询一致)
get_msg_chat_list - 在 中按
chats匹配chat_name - 匹配策略:
- 精确匹配唯一结果:直接使用
- 模糊匹配多个结果:展示候选列表让用户选择
- 无匹配结果:告知用户未找到
- 调用
- chat_type 判断:返回中不含会话类型字段,需根据上下文推断:用户明确提到「群」时使用
get_msg_chat_list,否则默认chat_type=2(单聊)chat_type=1
- When the user provides a person name or group name instead of an ID:
- Call to get the session list (the time range is consistent with the target query)
get_msg_chat_list - Match by in
chat_namechats - Matching strategy:
- Exact match with unique result: use directly
- Fuzzy match with multiple results: show the candidate list for the user to choose
- No matching result: inform the user that no match is found
- Call
- chat_type judgment: The return result of does not contain the session type field, which needs to be inferred from the context: use
get_msg_chat_listwhen the user explicitly mentions "group", otherwise default tochat_type=2(private chat)chat_type=1
userid转username
userid to username Conversion
流程:
- 调用 获取用户列表
wecomcli-lookup-contact get_userlist - 建立userid到username的映射关系
- 展示策略:
- 精确匹配:显示username
- 无匹配:保持显示userid
Process:
- Call to get the user list
wecomcli-lookup-contact get_userlist - Establish a mapping relationship from userid to username
- Display strategy:
- Exact match: display username
- No match: keep displaying userid
强制交互步骤(不可跳过)
Mandatory Interaction Steps (Cannot Be Skipped)
以下步骤在涉及非文本消息下载时必须逐一执行,不得合并、省略或跳过,即使用户未主动询问也必须执行:
- 必须主动告知文件位置:下载完成后必须立即向用户展示所有文件的完整路径和存放目录
- 必须询问是否删除:告知位置后必须立即询问用户是否需要清理临时文件
The following steps must be executed one by one when non-text message download is involved, and cannot be merged, omitted or skipped, even if the user does not actively ask:
- Must actively inform the file location: After the download is completed, you must immediately show the user the full path and storage directory of all files
- Must ask whether to delete: After informing the location, you must immediately ask the user whether to clean up the temporary files
典型工作流
Typical Workflows
查看会话列表
View Session List
用户query示例:
- "看看我最近一周有哪些聊天"
- "这几天谁给我发过消息"
执行流程:
- 确定时间范围(用户指定或默认最近7天)
- 调用 获取会话列表
get_msg_chat_list - 展示会话名称、最后消息时间、消息数量
- 若 为
has_more,告知用户还有更多会话可继续查看true
User query examples:
- "Check what chats I have had in the last week"
- "Who sent me messages these days"
Execution process:
- Determine the time range (specified by the user or default to the last 7 days)
- Call to get the session list
get_msg_chat_list - Display the session name, last message time, and number of messages
- If is
has_more, inform the user that there are more sessions available for viewingtrue
查看聊天记录
View Chat History
用户query示例:
- "帮我看看和张三最近的聊天记录"
- "看看项目群里最近的消息"
执行流程:
- 确定时间范围(用户指定或默认最近7天)
- 通过 chatid查找规则 确定目标会话的 和
chatidchat_type - 调用 拉取消息列表
get_message - 调用 的
wecomcli-lookup-contact获取通讯录,建立 userid→姓名 映射get_userlist - 统计非文本消息:遍历消息列表,统计 非
msgtype的消息(image/file/voice/video)数量和类型text - 展示消息时将 替换为可读姓名,格式:
userid- 文本消息:
姓名 [时间]: 内容 - 图片消息:
姓名 [时间]:[图片] - 文件消息:
姓名 [时间]:[文件] 文件名称 - 语音消息:
姓名 [时间]:[语音] 语音内容 - 视频消息:
姓名 [时间]:[视频]
- 文本消息:
- 非文本消息处理:展示完消息后,如果存在非文本消息:
- 主动询问是否下载:告知用户非文本消息数量和类型(如:"以上聊天中包含 2 张图片、1 个文件,是否需要下载到本地?")
- 用户确认后,逐个调用 接口,接口会自动下载文件并返回
get_msg_medialocal_path - 检查文件后缀:每个文件下载完成后,检查 对应的文件是否具有正确的后缀名:
local_path- 根据 返回的
get_msg_media(MIME 类型)和content_type字段判断: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
User query examples:
- "Help me check the recent chat history with Zhang San"
- "Check the recent messages in the project group"
Execution process:
- Determine the time range (specified by the user or default to the last 7 days)
- Determine the and
chatidof the target session through chatid search ruleschat_type - Call to pull the message list
get_message - Call of
get_userlistto get the address book, and establish a userid→name mappingwecomcli-lookup-contact - Count non-text messages: Traverse the message list, count the number and type of messages whose is not
msgtype(image/file/voice/video)text - Replace with a readable name when displaying messages, format:
userid- Text message:
Name [Time]: Content - Image message:
Name [Time]:[Image] - File message:
Name [Time]:[File] File name - Voice message:
Name [Time]:[Voice] Voice content - Video message:
Name [Time]:[Video]
- Text message:
- Non-text message processing: After displaying the messages, if there are non-text messages:
- Actively ask whether to download: Inform the user of the number and type of non-text messages (e.g.: "The above chat contains 2 pictures and 1 file, do you need to download them to the local disk?")
- After the user confirms, call the interface one by one, the interface will automatically download the file and return
get_msg_medialocal_path - Check file suffix: After each file is downloaded, check whether the file corresponding to has the correct suffix:
local_path- Judge according to the (MIME type) and
content_typefield returned byname:get_msg_media- If the file name lacks a suffix (e.g. instead of
screenshot), automatically add the correct suffix according toscreenshot.png(e.g.content_type→image/png,.png→application/pdf,.pdf→audio/amr,.amr→video/mp4).mp4 - If the file name suffix is inconsistent with , correct it based on
content_typecontent_type
- If the file name lacks a suffix (e.g.
- After completing or correcting the suffix, rename the file to the correct file name
- Confirm that the file can be read normally (file size > 0), if the file is empty or damaged, inform the user that the file download is abnormal
- Judge according to the
- ⚠️ Do not use the command for downloaded files: These files are historical attachments downloaded from chat records, you only need to inform the user of the local storage path, it is strictly forbidden to resend them to the user through the
MEDIA:commandMEDIA:
- ⚠️ Must actively inform the file location (this step cannot be skipped): After all files are downloaded and checked, you must immediately and actively show the user the file storage directory and the full path of each file in a summary form, do not wait 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 thedirectory.xxx/yyy/ - Image:
- ⚠️ Must ask whether to delete (this step cannot be skipped): After informing the file location, you must immediately and actively ask the user whether to delete the downloaded temporary files (e.g.: "If you no longer need these files, do you want me to clean them up for you?")
- After the user confirms deletion, delete the file corresponding to
local_path - Keep the file if the user does not need to delete it
- After the user confirms deletion, delete the file corresponding to
- If is not empty, inform the user that there are more messages available for viewing
next_cursor
发送消息
Send Message
用户query示例:
- "帮我给张三发一条消息:明天会议改到下午3点"
- "在项目群里发一条消息:今天下午3点开会"
执行流程:
- 通过 chatid查找规则 确定目标会话的 和
chatidchat_type - 发送前确认:向用户确认发送对象和内容(如:"即将向 张三 发送:'明天会议改到下午3点',确认发送吗?"),用户确认后再执行
- 调用 发送(
send_message固定为msgtype)text - 展示发送结果
User query examples:
- "Help me send a message to Zhang San: Tomorrow's meeting is rescheduled to 3 pm"
- "Send a message in the project group: There is a meeting at 3 pm today"
Execution process:
- Determine the and
chatidof the target session through chatid search ruleschat_type - Confirmation before sending: Confirm the sending object and content with the user (e.g.: "About to send to Zhang San: 'Tomorrow's meeting is rescheduled to 3 pm', confirm to send?"), execute after the user confirms
- Call to send (
send_messageis fixed asmsgtype)text - Display the sending result
查看消息并回复
View Messages and Reply
用户query示例:
- "看看张三给我发了什么,然后帮我回复收到"
执行流程:
- 先执行"查看聊天记录"流程(复用已获取的 和
chatid)chat_type - 展示消息后,执行"发送消息"流程(需确认后再发送)
User query example:
- "Check what Zhang San sent me, then help me reply received"
Execution process:
- First execute the "view chat history" process (reuse the obtained and
chatid)chat_type - After displaying the messages, execute the "send message" process (need to confirm before sending)
错误处理
Error Handling
- 时间范围超限:告知用户7天限制并调整为有效范围
- 会话未找到:明确告知用户未找到对应会话
- API错误:展示具体错误信息,必要时重试
- 网络问题:HTTP错误时主动重试最多3次`
- 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 corresponding session was not found
- API error: Display specific error information, retry if necessary
- Network problem: Actively retry up to 3 times when HTTP errors occur