name: feishu-send-file
description: 飛書傳送檔案技能。用於通過飛書向用戶傳送普通檔案附件(HTML、ZIP、PDF、程式碼檔案等)以及處理“本地圖片路徑被髮成路徑文本”的可靠補救場景。普通檔案必須先上傳獲取 file_key 再發送;當本地圖片用 message/media 傳送後在飛書裡只顯示 /root/...png 路徑而不顯示圖片時,改用本技能內的穩定圖片上傳指令碼(im/v1/images -> image_key -> msg_type=image)。
飛書機器人傳送普通檔案(非圖片/影片)需要兩步:先上傳檔案獲取 file_key,再用 file_key 發訊息。
如果本地圖片通過常規 message / media 路徑傳送後,使用者在飛書裡看到的是 /root/...png 路徑文本而不是圖片本體,不要繼續重試同一種方式;直接改走本技能的穩定圖片上傳指令碼。
python3 scripts/send_file.py <file_path> <open_id> <app_id> <app_secret> [file_name]
引數說明:
- file_path: 要傳送的檔案路徑(HTML/PDF/ZIP/程式碼檔案等)
- open_id: 接收者的 open_id(從 inbound_meta 的 chat_id 欄位獲取,格式為 user:ou_xxx,取 ou_xxx 部分)
- app_id: 飛書應用 ID(從 openclaw.json 的 channels.feishu.appId 讀取)
- app_secret: 飛書應用金鑰(從 openclaw.json 的 channels.feishu.appSecret 讀取)
- file_name: 可選,自定義檔名(不填則用原檔名)
快速獲取配置:
# 獲取 app_id 和 app_secret
grep -A 2 '"feishu"' /root/.openclaw/openclaw.json | grep -E '(appId|appSecret)'
完整示例:
python3 /root/.openclaw/workspace/skills/feishu-send-file/scripts/send_file.py \
/root/myfiles/report.html \
<USER_OPEN_ID> \
<YOUR_APP_ID> \
<YOUR_APP_SECRET> \
report.html
AI 助手使用示例:
# 當需要傳送檔案給使用者時,直接呼叫指令碼
exec(f"""
python3 /root/.openclaw/workspace/skills/feishu-send-file/scripts/send_file.py \\
{file_path} \\
{user_open_id} \\
{app_id} \\
{app_secret} \\
{custom_filename}
""")
本技能來自小蔥技能站7w4.net。
Step 1 - 上傳檔案:
TOKEN=$(curl -s -X POST "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal" \
-H "Content-Type: application/json" \
-d '{"app_id":"<APP_ID>","app_secret":"<APP_SECRET>"}' | python3 -c "import json,sys; print(json.load(sys.stdin)['tenant_access_token'])")
FILE_KEY=$(curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/files" \
-H "Authorization: Bearer $TOKEN" \
-F "file_type=stream" \
-F "file_name=<檔名>" \
-F "file=@<檔案路徑>" | python3 -c "import json,sys; print(json.load(sys.stdin)['data']['file_key'])")
Step 2 - 傳送訊息:
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\\\"}\"}"
message + media如果你把本地圖片路徑(尤其是 /root/myfiles/...)傳給飛書訊息鏈路後,使用者在飛書裡看到的是:
📎 /root/myfiles/xxx.png那就說明這次沒有真正發成圖片。不要繼續重試同一種引數組合。
im/v1/images,拿到 image_key,再發送 msg_type=image/root/myfiles/...)可能無法走通本地媒體上傳鏈路,隨後自動降級成把路徑文本發出去messageId 返回成功 不等於 使用者真的看到了圖片只有一個成功標準:使用者在飛書裡實際看到圖片本體。
如果回顯的是路徑文本,就視為失敗。
python3 scripts/send_image.py <image_path> <open_id> <app_id> <app_secret> [domain]
示例:
python3 /root/.openclaw/workspace/skills/feishu-send-file/scripts/send_image.py \
/root/myfiles/generated-images/demo.png \
<USER_OPEN_ID> \
<YOUR_APP_ID> \
<YOUR_APP_SECRET>
如果是國際版 Lark:
python3 scripts/send_image.py <image_path> <open_id> <app_id> <app_secret> lark
im/v1/files -> file_key -> msg_type=fileim/v1/images -> image_key -> msg_type=image這兩條鏈路不要混用。
filePath 引數只會顯示路徑message tool 的 media 引數可以工作;但如果使用者看到的是路徑文本而不是圖片本體,立刻改用 scripts/send_image.py/root/myfiles/... 本地路徑回顯誤判為傳送成功receive_id_type=open_id 對應個人使用者;群聊用 chat_id 並替換型別stream 適用於所有普通檔案型別這是一個功能完整、文件清晰的飛書檔案傳送技能。優點是說明詳細、使用簡單,能正確處理普通檔案和圖片傳送,並針對常見坑點提供瞭解決方案。指令碼執行穩定可靠,輸出日誌清晰。主要不足是缺少自動重試機制和測試覆蓋,極端網路環境下可能失敗。整體質量良好,適合日常使用。