通过 message 工具向飞书发送各类媒体文件。
所有媒体发送都通过 message 工具的 action=send,关键参数:
channel: feishutarget: chat:群ID 或 user:open_id(省略则回复当前会话)message: 附带的文字说明(可选)filePath: 本地文件路径(注意:飞书频道可能不支持)media: URL 地址(网络图片/文件)text
message action=send channel=feishu filePath=/path/to/file.pdf message="文件说明"
支持格式:pdf, doc/docx, xls/xlsx, ppt/pptx, txt, csv, zip, tar.gz 等。
text
message action=send channel=feishu filePath=/path/to/image.png message="图片说明"
支持格式:jpg, jpeg, png, gif, webp, bmp。
text
message action=send channel=feishu media=https://example.com/image.png message="网络图片"
⚠️ 注意:OpenClaw 飞书频道的 filePath 参数不支持本地视频文件。
需要用以下 exec+curl 方式发送视频:
bash
# 1. 获取 tenant_access_token(需要飞书应用的 appId 和 appSecret)
TOKEN_RESP=$(curl -s -X POST "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal" \
-H "Content-Type: application/json" \
-d '{"app_id":"你的appId","app_secret":"你的appSecret"}')
TOKEN=$(echo $TOKEN_RESP | grep -o '"tenant_access_token":"[^"]*"' | cut -d'"' -f4)
# 2. 上传视频文件(必须用 file_type=stream)
curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/files" \
-H "Authorization: Bearer $TOKEN" \
-F "file_type=stream" \
-F "file_name=视频文件名.mp4" \
-F "file=@/path/to/video.mp4"
# 3. 用返回的 file_key 发送消息
curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=open_id" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"receive_id": "用户的open_id",
"msg_type": "file",
"content": "{\"file_key\":\"返回的file_key\"}"
}'
关键点:
file_type 必须用 stream,不能用 mp4msg_type 用 file支持格式:mp4, mov, avi。
MP3 等音频文件作为普通文件发送:
text
message action=send channel=feishu filePath=/path/to/audio.mp3 message="音频文件"
语音消息需要 Ogg/Opus 格式。飞书会显示为可播放的语音条。
text
message action=send channel=feishu filePath=/path/to/voice.opus message="语音消息"
先用 ffmpeg 转换格式:
bash
ffmpeg -i input.mp3 -ar 16000 -ac 1 -acodec libopus output.ogg -y
然后发送 output.ogg。
语音消息的底层流程:
im.file.create, file_type: "opus",需带 duration(毫秒)msg_type: "audio",content: {"file_key":"xxx","duration":3007}当需要发送多个文件或不支持的格式时,先打包再发送:
bash
zip -j /tmp/archive.zip /path/to/file1 /path/to/file2
bash
tar czf /tmp/archive.tar.gz -C /path/to/dir .
text
message action=send channel=feishu filePath=/tmp/archive.zip message="打包文件"
类型格式发送方式飞书显示图片jpg/png/gif/webpfilePath 或 media(URL)内嵌图片文档pdf/doc/xls/pptfilePath文件卡片视频mp4/mov/aviexec+curl (file_type=stream)文件卡片音频mp3/wav/flacfilePath文件卡片语音opus/oggfilePath可播放语音条压缩包zip/tar.gzfilePath文件卡片网络图片URLmedia内嵌图片
im:message、 im:resource 权限filePath 不支持本地视频,必须用 exec+curl 方式上传后发送