详细分析 ▾
运行时依赖
版本
飞书语音消息技能初始发布。 - 向飞书(Lark)用户发送语音/音频消息,作为真实语音消息而非文件附件。 - 自动将 MP3、WAV 等音频转为 OPUS 格式(需 ffmpeg)。 - 需要飞书应用凭据及目标用户 Open ID。 - 包含音频转换与发送消息的逐步说明。 - 提供常见错误排查提示。
安装命令
点击复制技能文档
# Feishu 语音消息 Skill 本技能可通过 Open API 向飞书(Feishu/Lark)用户发送语音消息(非文件附件)。 ## 何时使用 当满足以下场景时使用本技能: - 用户想向飞书发送语音消息 - 用户希望将音频文件(MP3、WAV 等)转换并以语音消息形式发送 - 用户明确要求发送音频消息,而非文件上传 ## 依赖 1. ffmpeg —— 用于将音频转换为 OPUS 格式 2. Node.js 18+ —— 运行发送脚本 3. 飞书应用凭证: - App ID - App Secret - 目标用户的 Open ID ## 工作原理 1. 音频转 OPUS —— 飞书要求音频必须为 OPUS 格式 2. 上传音频文件 —— 以 file_type: opus 及时长上传至飞书 3. 发送语音消息 —— 使用 msg_type: audio 发送 ## 使用方法 ### 步骤 1:将音频转为 OPUS ``bash ffmpeg -i input.mp3 -c:a libopus -b:a 32k output.opus ` ### 步骤 2:获取音频时长 `bash ffprobe -v quiet -show_format -print_format json input.mp3 # 在输出中查找 "duration" 字段 ` ### 步骤 3:运行脚本 `bash node scripts/send-voice.mjs \ --app-id "cli_xxx" \ --app-secret "xxx" \ --user-id "ou_xxx" \ --audio-file "audio.opus" \ --duration 3480 ` 或使用环境变量: `bash export FEISHU_APP_ID="cli_xxx" export FEISHU_APP_SECRET="xxx" node scripts/send-voice.mjs --user-id "ou_xxx" --audio-file "audio.opus" --duration 3480 ` ## API 详情 ### 1. 获取 Tenant Access Token ` POST https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal ` ### 2. 上传音频文件 ` POST https://open.feishu.cn/open-apis/im/v1/files Content-Type: multipart/form-data file_type: opus file_name: voice.opus duration: file: ` ### 3. 发送语音消息 ` POST https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=open_id { "receive_id": "ou_xxx", "msg_type": "audio", "content": "{\"file_key\":\"file_v3_xxx\"}" } ` ## 重要说明 - 音频必须为 OPUS 格式 —— MP3/WAV 会失败 - 时长单位为毫秒 - 应用必须开启机器人能力 - 频率限制:每用户/每会话 5 QPS ## 示例输出 ` 🎤 开始发送语音消息到飞书... 📁 音频文件: /path/to/voice.opus ⏱️ 时长: 3480ms ✅ 获取 Tenant Access Token 成功 ✅ 上传语音文件成功, file_key: file_v3_00uh_xxx ✅ 发送语音消息成功! 消息 ID: om_x100b5731827e6ca4b10d48c15dfa3ab 🎉 完成! ` ## 故障排查 | 错误 | 解决方案 | |-------|----------| | file type not support | 转换为 OPUS 格式 | | duration is required | 添加时长参数 | | permission denied | 检查应用是否拥有消息权限 | | user not found` | 校验用户 Open ID |