feishu-send-file

👤 dadaniya99 📦 v1.2.1 ⭐ 4.5 ⬇️ 3.6K 下載
📄 辦公效率 免費 🔑 需 API Key

📖 技能介紹


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.jsonchannels.feishu.appId 讀取) - app_secret: 飛書應用金鑰(從 openclaw.jsonchannels.feishu.appSecret 讀取) - file_name: 可選,自定義檔名(不填則用原檔名)

快速獲取配置:

# 獲取 app_id 和 app_secret
grep -A 2 '"feishu"' /root/.openclaw/openclaw.json | grep -E '(appId|appSecret)'

小蔥技能7w4.net有完整的技能分類。

完整示例:

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}
""")

方式二:手動兩步

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\\\"}\"}"

穩定傳送圖片(2026-03-15 補充)

什麼時候不要再硬用 message + media

如果你把本地圖片路徑(尤其是 /root/myfiles/...)傳給飛書訊息鏈路後,使用者在飛書裡看到的是:

  • 📎 /root/myfiles/xxx.png
  • 或純本地路徑文本

那就說明這次沒有真正發成圖片。不要繼續重試同一種引數組合。

原因(真實世界版)

  • 飛書真正的圖片訊息不是“把本地路徑塞給訊息傳送器”
  • 正路是:先上傳到 im/v1/images,拿到 image_key,再發送 msg_type=image
  • OpenClaw / Feishu 外掛在某些本地路徑場景下(特別是 /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=file
  • 圖片im/v1/images -> image_key -> msg_type=image

這兩條鏈路不要混用。

注意事項

  • 普通檔案:必須走本技能的兩步流程,直接用 filePath 引數只會顯示路徑
  • 圖片:理論上 message tool 的 media 引數可以工作;但如果使用者看到的是路徑文本而不是圖片本體,立刻改用 scripts/send_image.py
  • 不要把 /root/myfiles/... 本地路徑回顯誤判為傳送成功
  • receive_id_type=open_id 對應個人使用者;群聊用 chat_id 並替換型別
  • 飛書 file_type 用 stream 適用於所有普通檔案型別

🤖 AI 評測

這是一個功能完整、文件清晰的飛書檔案傳送技能。優點是說明詳細、使用簡單,能正確處理普通檔案和圖片傳送,並針對常見坑點提供瞭解決方案。指令碼執行穩定可靠,輸出日誌清晰。主要不足是缺少自動重試機制和測試覆蓋,極端網路環境下可能失敗。整體質量良好,適合日常使用。

📊 多維度評分

適應性4.7
規範性4.3
有效性4.7
可靠性4.1
可信度5

📁 包含檔案 (5 個)

📄 SKILL.md 5.2 KB
📄 _meta.json 135 B
📄 scripts/send_file.py 2.8 KB
📄 scripts/send_image.py 3.7 KB
📄 skill.json 503 B