Feishu Media Sender
Send multimedia messages to Feishu with proper formatting: inline images, voice bubbles, video players, rich text, and cards.
Dependencies
- -
ffmpeg at D:\ffmpeg\bin\ffmpeg.exe (for audio conversion, video fix) - INLINECODE2 at
D:\ffmpeg\bin\ffprobe.exe (for duration detection) - Python 3.7+
- Feishu app credentials (pre-configured in script defaults)
Quick Reference
Run the script at scripts/feishu_media.py:
CODEBLOCK0
Available Functions
| Function | Message Type | Key Features |
|---|
| INLINECODE5 | text | Plain text |
| INLINECODE6 |
image | Inline embed, auto-detect mime |
|
send_audio(filepath) | audio | Voice bubble, auto→opus, auto duration |
|
send_video(filepath, cover_image=None) | media | Inline player, faststart, auto duration |
|
send_rich_text(title, elements) | post | Rich text with embedded media |
|
send_card(title, elements) | interactive | Card with header color |
All functions accept optional: open_id, token, app_id, app_secret.
Key Rules (learned from testing)
- 1. Audio: Must be opus format, must include
duration (ms). Auto-converts non-opus via ffmpeg. - Video: Must upload as
file_type=mp4, must include duration (ms). Script auto-applies -movflags +faststart. - Video message type: Use
msg_type=media (not video), content uses file_key + optional image_key for cover. - Image in video:
image_key is the cover thumbnail. Without it, video has no preview frame. - Rich text media: Use
{'tag': 'media', 'file_key': '...', 'image_key': '...'} as an independent paragraph. - File upload types:
opus (audio), mp4 (video), stream (generic file), pdf, doc, xls, ppt.
Example: Send MiniMax content to Feishu
CODEBLOCK1
CLI Usage
CODEBLOCK2
技能名称: ali-feishu-sender
详细描述:
飞书多媒体发送器
向飞书发送格式规范的多媒体消息:内嵌图片、语音气泡、视频播放器、富文本和卡片。
依赖项
- - ffmpeg 位于 D:\ffmpeg\bin\ffmpeg.exe(用于音频转换、视频修复)
- ffprobe 位于 D:\ffmpeg\bin\ffprobe.exe(用于时长检测)
- Python 3.7+
- 飞书应用凭证(已在脚本默认配置中预置)
快速参考
运行位于 scripts/feishu_media.py 的脚本:
python
import sys; sys.path.insert(0, rdir>/scripts); from feishumedia import *
可用函数
| 函数 | 消息类型 | 主要特性 |
|---|
| sendtext(text) | 文本 | 纯文本 |
| sendimage(filepath) |
图片 | 内嵌显示,自动检测MIME类型 |
| send_audio(filepath) | 音频 | 语音气泡,自动转opus格式,自动获取时长 |
| send
video(filepath, coverimage=None) | 媒体 | 内嵌播放器,faststart优化,自动获取时长 |
| send
richtext(title, elements) | 富文本 | 支持嵌入媒体的富文本 |
| send_card(title, elements) | 交互式 | 带标题颜色的卡片 |
所有函数均支持可选参数:openid、token、appid、app_secret。
关键规则(经测试总结)
- 1. 音频:必须为opus格式,必须包含duration(毫秒)。非opus格式通过ffmpeg自动转换。
- 视频:必须以filetype=mp4上传,必须包含duration(毫秒)。脚本自动应用-movflags +faststart。
- 视频消息类型:使用msgtype=media(而非video),内容使用filekey加可选封面imagekey。
- 视频中的图片:imagekey为封面缩略图。缺少则视频无预览帧。
- 富文本媒体:使用{tag: media, filekey: ..., image_key: ...}作为独立段落。
- 文件上传类型:opus(音频)、mp4(视频)、stream(通用文件)、pdf、doc、xls、ppt。
示例:将MiniMax内容发送至飞书
python
图片
send_image(minimax-output/kitten.png)
TTS语音气泡(自动将mp3转换为opus)
send_audio(minimax-output/greeting.mp3)
带封面的视频(自动faststart优化+时长检测)
send
video(minimax-output/kittenvideo.mp4, cover_image=minimax-output/kitten.png)
带视频的富文本
send
richtext(阿离的报告, [
[{tag: text, text: 一舞剑气动四方~}],
[{tag: media, file
key: filexxx, image
key: imgxxx}],
])
命令行使用
bash
python scripts/feishu_media.py text Hello
python scripts/feishu_media.py image photo.png
python scripts/feishu_media.py audio greeting.mp3
python scripts/feishu_media.py video clip.mp4 --cover thumb.png