飛書圖片傳送

👤 moistenxx 📦 v1.0.0 ⭐ 4.2 ⬇️ 761 下載
💻 開發程式設計 免費 🔑 需 API Key

📖 技能介紹


name: feishu-image-sender description: 直接通過飛書開放平臺 API 傳送圖片(繞過 OpenClaw 外掛的限制),而非以檔案附件形式傳送。使用場景:需要傳送截圖、二維碼等圖片給使用者時。

7w4.net有更好的技能外掛。


feishu-image-sender

通過飛書開放平臺 API 直接傳送圖片到使用者,圖片以內嵌方式顯示,而非檔案附件。

核心邏輯

兩步走: 1. 上傳圖片到飛書伺服器,獲取 image_key 2. 用 image_key 發一條 image 型別訊息

操作步驟

第一步:獲取 Access 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>"}'

響應:{"code":0,"tenant_access_token":"t-xxx","expire":3339}

記錄返回的 tenant_access_token

第二步:上傳圖片

curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/images" \
  -H "Authorization: Bearer <tenant_access_token>" \
  -F "image_type=message" \
  -F "image=@/path/to/image.png"

響應:{"code":0,"data":{"image_key":"img_v3_xxx"},"msg":"success"}

記錄返回的 image_key

第三步:傳送圖片訊息

curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=open_id" \
  -H "Authorization: Bearer <tenant_access_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "receive_id": "<open_id>",
    "msg_type": "image",
    "content": "{\"image_key\":\"<image_key>\"}"
  }'

receive_id 可選 open_id(使用者唯標識)、chat_id(群會話)、user_idunion_id

響應成功:{"code":0,"data":{"message_id":"om_xxx",...}}

完整示例(單次執行)

#!/bin/bash
# 引數
IMAGE_PATH="$1"
OPEN_ID="$2"
APP_ID="cli_a924632610b8dbd9"
APP_SECRET="c3TXscIJPF1f8jcQ4mJJegNVk72ktbwK"

# 1. 獲取 token
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 sys,json; print(json.load(sys.stdin)['tenant_access_token'])")

# 2. 上傳圖片
IMAGE_KEY=$(curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/images" \
  -H "Authorization: Bearer $TOKEN" \
  -F "image_type=message" \
  -F "image=@$IMAGE_PATH" | \
  python3 -c "import sys,json; print(json.load(sys.stdin)['data']['image_key'])")

# 3. 傳送圖片
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\":\"image\",\"content\":\"{\\\"image_key\\\":\\\"$IMAGE_KEY\\\"}\"}"

echo "Done: $IMAGE_KEY"

工具呼叫封裝(Node.js)

const fs = require('fs');
const path = require('path');

async function feishuSendImage(imagePath, openId, appId, appSecret) {
  // 1. get token
  const tokenRes = await fetch('https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ app_id: appId, app_secret: appSecret })
  });
  const { tenant_access_token } = await tokenRes.json();

  // 2. upload image
  const imageBuffer = fs.readFileSync(imagePath);
  const uploadRes = await fetch('https://open.feishu.cn/open-apis/im/v1/images', {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${tenant_access_token}` },
    body: (() => {
      const form = new FormData();
      form.append('image_type', 'message');
      form.append('image', new Blob([imageBuffer]), path.basename(imagePath));
      return form;
    })()
  });
  const { data: { image_key } } = await uploadRes.json();

  // 3. send image message
  const sendRes = await fetch(`https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=open_id`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${tenant_access_token}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      receive_id: openId,
      msg_type: 'image',
      content: JSON.stringify({ image_key })
    })
  });
  return sendRes.json();
}

限制與注意事項

  • 圖片大小限制:每個檔案最大 30MB
  • 支援格式:jpg、png、gif、webp、bmp、heic
  • token 有效期 2 小時,超時需重新獲取
  • receive_id_type 必須與 receive_id 匹配(open_id / user_id / chat_id / union_id)
  • 圖片訊息不能通過 web 預覽,必須是桌面端或手機端才能直接檢視

🤖 AI 評測

這是一個功能完整的飛書圖片傳送技能,文件寫得清晰明白,步驟講解詳細,還提供了現成的程式碼示例,上手比較快。主要問題是程式碼裡直接寫了金鑰憑證,存在安全隱患;另外缺少對 API 調用出錯的處理,網路不好時可能出問題。整體質量中等偏上,功能能用,但安全性和健壯性還需要加強。推薦指數:★★★☆☆

📊 多維度評分

適應性3.8
規範性4.2
有效性4.2
可靠性3.7
可信度5

📁 包含檔案 (2 個)

📄 SKILL.md 4.5 KB
📄 _meta.json 137 B