飞书文件发送技能(安全版)
v1发送 files, images, and audio messages via Feishu Lark API using the mandatory two-step process. Use when needing to 发送 files, images, or voice messages to Feishu users or groups. This 技能 enforces the required 工作流 - first 上传 to 获取 file_key, image_key, or audio_key, then 发送 message with the key. Supports file API for documents, image API for pictures, and file API with audio type for voice messages.
运行时依赖
安装命令
点击复制技能文档
飞书文件/图片发送 技能 快速开始
- 配置文件
复制示例配置文件:
cd ~/.OpenClaw/workspace/技能s/feishu-发送-file cp config.json.example config.json # 使用你喜欢的编辑器修改 config.json
填入你的配置:
{ "应用_id": "命令行工具_xxxxxxxxxxxxxxxx", "应用_secret": "your_应用_secret_here", "接收_id": "ou_xxxxxxxxxxxxxxxx", "message_mode": "发送" }
配置说明:
字段 说明 示例 应用_id 飞书应用ID 命令行工具_xxxxxxxxxxxxxxxx 应用_secret 飞书应用密钥 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 接收_id 接收人Open ID ou_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx message_mode 消息模式:发送 = 直接发送 发送
⚠️ 重要:本脚本只支持发送模式 (发送),不支持回复模式 (reply),避免消息被标记为回复。
安全提示:
config.json 已被添加到 .gitignore,不会意外提交到 Git 建议使用环境变量方式,避免在文件中存储凭证
- 发送消息
# 发送文本 ./scripts/发送-message.sh text "你好主人!"
# 发送 Markdown 卡片 ./scripts/发送-message.sh card "加粗 和 斜体"
# 发送图片 ./scripts/发送-message.sh image "/path/to/photo.png"
# 发送语音(opus格式) ./scripts/发送-message.sh audio "/path/to/voice.opus"
# 发送视频 ./scripts/发送-message.sh video "/path/to/video.mp4"
# 发送文件 ./scripts/发送-message.sh file "/path/to/document.pdf"
- 环境变量方式(推荐)
使用环境变量临时覆盖配置文件:
导出 FEISHU_应用_ID="命令行工具_xxx" 导出 FEISHU_应用_SECRET="xxx" 导出 FEISHU_接收_ID="ou_xxx"
./scripts/发送-message.sh text "消息内容"
优先级:环境变量 > 配置文件
⚠️ CRITICAL: OpenClaw 自动回复陷阱 问题描述
OpenClaw 的消息回复机制会自动将响应关联到用户消息,导致变成「回复」而不是「发送」!
即使你用 curl 调用 API,如果最后通过 OpenClaw 的 normal 回复输出,系统仍可能标记为 has_reply_上下文: true。
解决方案:使用独立脚本
必须 使用提供的独立脚本 发送-message.sh,它完全绕过 OpenClaw 的回复机制:
# ✅ 正确:使用独立脚本(绕过 OpenClaw 回复) ./scripts/发送-message.sh text "你好主人!" ./scripts/发送-message.sh image "/path/to/image.png" ./scripts/发送-message.sh audio "/path/to/voice.opus"
不要 这样做:
# ❌ 错误:即使 curl 成功,最后通过 OpenClaw 回复输出,仍会变成「回复」 curl -X POST ... echo "发送成功" # 这行输出会被 OpenClaw 标记为回复
⚠️ 重要警告
- 发送消息 vs 回复消息
必须使用「发送消息」API,不要混用「回复消息」API
用途 API URL 说明 ✅ 发送消息 发送消息 POST /im/v1/messages 本技能使用,直接发送消息 ❌ 回复消息 回复消息 POST /im/v1/messages/:message_id/reply 不使用,用于回复指定消息
正确的发送消息 URL:
POST https://open.feishu.cn/open-APIs/im/v1/messages?接收_id_type=open_id
错误的回复消息 URL:
# 不要用这个! POST https://open.feishu.cn/open-APIs/im/v1/messages/:message_id/reply
- 必须使用两步流程
飞书发送文件/图片必须使用两步流程,一步都不能少!
❌ 错误方式:直接通过 message API 发送文件路径 ✅ 正确方式:先上传获取 file_key/image_key,再用 key 发送消息
三种API的区别 类型 上传API 消息类型 返回key 适用场景 图片 /im/v1/images image image_key jpg/png/gif等图片 文件 /im/v1/files file file_key 文档、压缩包等 语音 /im/v1/files audio/file file_key opus/mp3音频 视频 /im/v1/files media file_key mp4视频 表情包 /im/v1/images image image_key png/gif表情包 图片发送流程 第一步:上传图片获取 image_key curl -X POST "https://open.feishu.cn/open-APIs/im/v1/images" \ -H "Authorization: Bearer $令牌" \ -F "image_type=message" \ -F "image=@/path/to/image.jpg"
响应示例:
{ "code": 0, "data": { "image_key": "img_v3_02ve_xxxx-xxxx-xxxx-xxxx" } }
关键点:
image_type 必须是 message image 使用 @ 符号指定本地图片路径 保存返回的 image_key,下一步要用 第二步:发送图片消息 curl -X POST "https://open.feishu.cn/open-APIs/im/v1/messages?接收_id_type=open_id" \ -H "Authorization: Bearer $令牌" \ -H "Content-Type: 应用/json" \ -d '{ "接收_id": "ou_xxxxxx", "msg_type": "image", "content": "{\"image_key\":\"img_v3_02ve_xxxx-xxxx-xxxx-xxxx\"}" }'
文件发送流程 第一步:上传文件获取 file_key curl -X POST "https://open.feishu.cn/open-APIs/im/v1/files" \ -H "Authorization: Bearer $令牌" \ -F "file_type=流" \ -F "file_name=文件名.md" \ -F "file=@/path/to/file"
响应示例:
{ "code": 0, "data": { "file_key": "file_v3_00ve_xxxx-xxxx-xxxx-xxxx" } }
关键点:
file_type 必须是 流 file_name 必须包含扩展名 file 使用 @ 符号指定本地文件路径 第二步:发送文件消息 curl -X POST "https://open.feishu.cn/open-APIs/im/v1/messages?接收_id_type=open_id" \ -H "Authorization: Bearer $令牌" \ -H "Content-Type: 应用/json" \ -d '{ "接收_id": "ou_xxxxxx", "msg_type": "file", "content": "{\"file_key\":\"file_v3_00ve_xxxx-xxxx-xxxx-xxxx\"}" }'
完整参数说明 获取 tenant_访问_令牌
所有API调用都需要先获取令牌:
curl -X POST "https://open.feishu.cn/open-APIs/auth/v3/tenant_访问_令牌/internal" \ -H "Content-Type: 应用/json" \ -d '{ "应用_id": "命令行工具_xxxxx", "应用_secret": "xxxxx" }'
接收_id_type 选项 类型 说明 示例 open_id 用户的唯一标识(推荐) ou_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx user_id 用户ID user_xxxxx union_id 统一ID on_xxxxx emAIl 邮箱 user@company.com chat_id 群聊ID oc_xxxxx 使用脚本自动发送
本技能包含自动化脚本:
发送图片 ./scripts/发送-image.sh <应用_id> <应用_secret> <接收_id>
发送文件 ./scripts/发送-file.sh <应用_id> <应用_secret> <接收_id>
发送语音 ./scripts/发送-audio.sh <应用_id> <应用_secret> <接收_id>
环境变量方式 导出 FEISHU_应用_ID="命令行工具_xxxxx" 导出 FEISHU_应用_SECRET="xxxxx" ./scripts/发送-image.sh "" "" "ou_xxxxx" "/path/to/image.jpg" ./scripts/发送-file.sh "" "" "ou_xxxxx" "/path/to/file.pdf" ./scripts/发送-audio.sh "" "" "ou_xxxxx" "/path/to/voice.opus"
常见错误 错误 原因 解决 field 验证 fAIled 缺少 接收_id_type URL必须加 ?接收_id_type=open_id invalid file_key file_key格式错误或已过期 重新上传文件获取新key invalid image_key image_key格式错误或已过期 重新上传图片获取新key 权限 denied 应用没有权限 检查应用权