Skill: franklu0819-lang/feishu-file (version 1.0.1)

--- name: feishu-file description: Send local files to Feishu chats. Supports uploading and sending any file type as a Feishu file message. metadata: { "openclaw": { "requires": { "bins": ["curl", "jq"], "env": ["FEISHU_APP_ID", "FEISHU_APP_SECRET"] } } } --- # Feishu File Sender A skill to send local files to Feishu users or groups. ## Setup Requires Feishu App credentials. Ensure these are set in your environment or `openclaw.json`: ```bash export FEISHU_APP_ID="cli_xxx" export FEISHU_APP_SECRET="xxx" export FEISHU_RECEIVER="ou_xxx" # Default receiver (optional) ``` ## Usage ### Basic Usage Send a file to the default receiver (configured in `FEISHU_RECEIVER`): ```bash bash scripts/send_file.sh "/path/to/your/file.pdf" ``` ### Specific Receiver Send to a specific OpenID: ```bash bash scripts/send_file.sh "/path/to/report.xlsx" "ou_abcdef123456" ``` ### Different Receiver Types Send to a Group (chat_id): ```bash bash scripts/send_file.sh "/path/to/archive.zip" "oc_abcdef123456" "chat_id" ``` Supported types: `open_id`, `user_id`, `chat_id`, `email`. ## Script Details ### scripts/send_file.sh The main script that handles the 3-step process: 1. **Auth**: Obtains a `tenant_access_token`. 2. **Upload**: Uploads the file to Feishu's internal storage using `POST /im/v1/files`. 3. **Send**: Sends the file message using `POST /im/v1/messages`. ## Permissions Required The Feishu App must have the following permissions: - `im:message` (Send and receive messages) - `im:message:send_as_bot` (Send messages as bot) - `im:resource` (Access and upload resources)

path: _meta.json
content: id: feishu-file
name: Feishu File Sender
author: Neo
category: Communication

path: package.json
content: {
  "name": "feishu-file",
  "version": "1.0.1",
  "description": "Send local files to Feishu",
  "scripts": {
    "send": "bash scripts/send_file.sh"
  },
  "dependencies": {}
}


path: scripts/send_file.sh
content: #!/bin/bash
# Feishu File Sender Skill Script
# Uploads a local file to Feishu and sends it as a message to a specific receiver.

set -e

# Configuration
# These should be passed as environment variables or arguments
# APP_ID="${FEISHU_APP_ID}"
# APP_SECRET="${FEISHU_APP_SECRET}"
# RECEIVER="${FEISHU_RECEIVER}"

# Arguments
FILE_PATH="$1"
RECEIVER_ID="$2"
RECEIVER_TYPE="${3:-open_id}" # default to open_id, others: user_id, chat_id, email

if [ -z "$FILE_PATH" ]; then
    echo "❌ Error: Missing file path"
    echo "Usage: $0 <file_path> [receiver_id] [receiver_type]"
    exit 1
fi

if [ ! -f "$FILE_PATH" ]; then
    echo "❌ Error: File not found: $FILE_PATH"
    exit 1
fi

# Use environment variables if receiver id is not provided as argument
if [ -z "$RECEIVER_ID" ]; then
    RECEIVER_ID="${FEISHU_RECEIVER}"
fi

if [ -z "$RECEIVER_ID" ]; then
    echo "❌ Error: Missing receiver ID (provide as argument or set FEISHU_RECEIVER env var)"
    exit 1
fi

# Use credentials from environment or fallback to OpenClaw config if possible
# Note: In OpenClaw exec context, FEISHU_APP_ID/SECRET are usually available if configured
if [ -z "$FEISHU_APP_ID" ] || [ -z "$FEISHU_APP_SECRET" ]; then
    echo "❌ Error: Missing FEISHU_APP_ID or FEISHU_APP_SECRET environment variables"
    exit 1
fi

FILE_NAME=$(basename "$FILE_PATH")

echo "📂 Sending file: $FILE_NAME to $RECEIVER_ID ($RECEIVER_TYPE)"

# 1. Get Tenant Access Token
echo "🔑 Getting access token..."
TOKEN_RESPONSE=$(curl -s -X POST "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal" \
    -H "Content-Type: application/json" \
    -d "{\"app_id\": \"$FEISHU_APP_ID\", \"app_secret\": \"$FEISHU_APP_SECRET\"}")

[REDACTED_SECRET] "$TOKEN_RESPONSE" | jq -r '.tenant_access_token')

if [ "$TOKEN" = "null" ] || [ -z "$TOKEN" ]; then
    echo "❌ Failed to get token"
    echo "$TOKEN_RESPONSE" | jq .
    exit 1
fi

# 2. Upload file to Feishu
echo "📤 Uploading file to Feishu..."
UPLOAD_RESPONSE=$(curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/files" \
    -H "Authorization: Bearer $TOKEN" \
    -F "file_type=stream" \
    -F "file_name=$FILE_NAME" \
    -F "file=@$FILE_PATH")

UPLOAD_CODE=$(echo "$UPLOAD_RESPONSE" | jq -r '.code')
if [ "$UPLOAD_CODE" != "0" ]; then
    echo "❌ File upload failed"
    echo "$UPLOAD_RESPONSE" | jq .
    exit 1
fi

FILE_KEY=$(echo "$UPLOAD_RESPONSE" | jq -r '.data.file_key')
echo "✅ File uploaded (file_key: $FILE_KEY)"

# 3. Send message
echo "📨 Sending message..."
SEND_RESPONSE=$(curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=$RECEIVER_TYPE" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d "{
        \"receive_id\": \"$RECEIVER_ID\",
        \"msg_type\": \"file\",
        \"content\": \"{\\\"file_key\\\": \\\"$FILE_KEY\\\"}\"
    }")

SEND_CODE=$(echo "$SEND_RESPONSE" | jq -r '.code')
if [ "$SEND_CODE" != "0" ]; then
    echo "❌ Failed to send message"
    echo "$SEND_RESPONSE" | jq .
    exit 1
fi

echo "🎉 Success! File $FILE_NAME sent to $RECEIVER_ID"


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: suspicious | SkillSpector: suspicious (HIGH)