Feishu CLI 消息命令
通过命令行或 AI Agent 自动化,发送消息、管理群聊、搜索对话、回复话题和下载媒体文件。
概述
终端中的即时通讯
Feishu CLI 消息模块提供 10 个快捷命令,实现全面的即时通讯管控。向群聊或个人用户发送文本、Markdown、图片和文件。管理群组创建、搜索消息历史、处理媒体下载——所有操作均可通过命令行或 AI Agent 自动化完成。每个快捷命令直接映射到飞书开放平台 IM API,为您提供对 Feishu/Lark 消息系统的完整编程访问。
发送消息
+messages-send — 向群聊或用户发送消息
向任意群聊或个人用户发送文本、Markdown、图片、文件、视频或音频。默认使用机器人身份发送。可以使用 --chat-id 指定群聊,或使用 --user-id 指定特定用户。
$ lark-cli im +messages-send --chat-id "oc_xxx" --text "Hello team"
$ lark-cli im +messages-send --user-id "ou_xxx" --markdown "**Important update**: Deploy completed successfully."
$ lark-cli im +messages-send --chat-id "oc_xxx" --image ./screenshot.png
$ lark-cli im +messages-send --chat-id "oc_xxx" --file ./report.pdf
$ lark-cli im +messages-send --chat-id "oc_xxx" --content '{"text":"Custom payload"}' --idempotency-key "unique-key-001"
支持的参数
| 参数 | 说明 |
--chat-id | 目标群聊 ID(oc_xxx 格式) |
--user-id | 目标用户 ID,用于私聊消息(ou_xxx 格式) |
--text | 发送纯文本消息 |
--markdown | 发送 Markdown 格式消息 |
--image | 发送图片文件(本地路径) |
--file | 发送文件附件(本地路径) |
--video | 发送视频文件(本地路径) |
--audio | 发送音频文件(本地路径) |
--content | 发送原始 JSON 内容载荷 |
--idempotency-key | 唯一键,防止重复发送 |
身份:仅限机器人身份(--as bot)。发送者名称显示为机器人配置的名称。
回复消息
+messages-reply — 回复话题
通过消息 ID 回复特定消息。支持与 +messages-send 相同的所有内容类型。回复将以话题形式出现在对话中。
$ lark-cli im +messages-reply --message-id "om_xxx" --text "Got it, thanks!"
$ lark-cli im +messages-reply --message-id "om_xxx" --markdown "Resolved in commit `a1b2c3d`"
搜索消息
+messages-search — 搜索消息历史
跨消息历史进行全文搜索。按群聊、发送者和日期范围进行筛选。需要用户身份——机器人身份不支持搜索。
$ lark-cli im +messages-search --query "quarterly report" --chat-id "oc_xxx"
$ lark-cli im +messages-search --query "deployment" --sender "ou_xxx" --start "2026-03-01" --end "2026-03-30"
$ lark-cli im +messages-search --query "bug fix" --page-token "next_page_token_abc"
参数
| 参数 | 说明 |
--query | 搜索查询字符串(必填) |
--chat-id | 将搜索限制在特定群聊 |
--sender | 按发送者用户 ID 筛选 |
--start | 日期范围筛选的起始日期 |
--end | 日期范围筛选的结束日期 |
--page-token | 下一页的分页令牌 |
身份:仅限用户身份。机器人身份无法执行消息搜索。
列出群聊消息
+chat-messages-list — 列出群聊中的消息
获取群聊或单聊中指定日期范围内的所有消息。使用 --chat-id 指定群聊,或使用 --user-id 查看私聊历史。
$ lark-cli im +chat-messages-list --chat-id "oc_xxx" --start "2026-03-01" --end "2026-03-30"
$ lark-cli im +chat-messages-list --user-id "ou_xxx" --start "2026-03-01" --end "2026-03-30"
创建群聊
+chat-create — 创建新群聊
通过编程方式创建群聊,设置名称、描述和初始成员。使用机器人身份。
$ lark-cli im +chat-create --name "Project Alpha" --description "Team discussion" --users "ou_xxx,ou_yyy"
$ lark-cli im +chat-create --name "Daily Standup"
搜索群聊
+chat-search — 搜索群聊
按名称或关键词搜索群聊。适用于在发送消息前查找正确的群聊 ID。
$ lark-cli im +chat-search --query "engineering"
更新群聊
+chat-update — 更新群聊设置
在群聊创建后修改其名称、描述或其他设置。
$ lark-cli im +chat-update --chat-id "oc_xxx" --name "New Name" --description "Updated description"
下载媒体
+messages-resources-download — 下载消息附件
下载消息中附带的图片、文件和其他媒体。需要消息 ID、文件密钥和资源类型。
$ lark-cli im +messages-resources-download --message-id "om_xxx" --file-key "xxx" --type image
$ lark-cli im +messages-resources-download --message-id "om_xxx" --file-key "yyy" --type file
话题消息
+threads-messages-list — 列出话题中的消息
获取特定消息话题中的所有回复。话题通过话题 ID(ot_xxx 格式)标识。
$ lark-cli im +threads-messages-list --thread "ot_xxx"
批量获取消息
+messages-mget — 批量获取消息
通过单次请求按消息 ID 批量获取多条消息。无需列出整个群聊即可高效获取特定消息。
$ lark-cli im +messages-mget --message-ids "om_xxx,om_yyy"
身份与权限
机器人身份 vs 用户身份
Feishu CLI 消息命令在两种身份模式下运行。了解两者的区别对于选择正确的方式至关重要。
| 功能 | 机器人身份 | 用户身份 |
| 发送消息 | 支持 | 不支持 |
| 回复消息 | 支持 | 不支持 |
| 搜索消息 | 不支持 | 支持 |
| 创建群聊 | 支持 | 不支持 |
| 列出群聊消息 | 支持 | 支持 |
| 下载媒体 | 支持 | 支持 |
使用机器人身份时,发送者名称为机器人配置的显示名称。若需在列出的消息中解析人类可读的发送者名称,可能需要通过通讯录 API 交叉引用用户 ID。
命令参考
所有消息快捷命令
| 快捷命令 | 说明 | 风险等级 | 关键参数 |
+messages-send | 向群聊或用户发送消息 | 低 | --chat-id, --user-id, --text, --markdown, --image, --file |
+messages-reply | 回复特定消息 | 低 | --message-id, --text, --markdown |
+messages-search | 跨消息全文搜索 | 安全 | --query, --chat-id, --sender, --start, --end |
+chat-messages-list | 列出群聊中的消息 | 安全 | --chat-id, --user-id, --start, --end |
+chat-create | 创建新群聊 | 中 | --name, --description, --users |
+chat-search | 搜索群聊 | 安全 | --query |
+chat-update | 更新群聊名称或描述 | 中 | --chat-id, --name, --description |
+messages-resources-download | 下载消息附件 | 安全 | --message-id, --file-key, --type |
+threads-messages-list | 列出话题中的消息 | 安全 | --thread |
+messages-mget | 按 ID 批量获取消息 | 安全 | --message-ids |