feishu-image

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Feishu Image Sender

飞书图片发送工具

Send images to Feishu (Lark) conversations. This skill works both inside OpenClaw and as a standalone CLI tool.
向飞书(Lark)会话发送图片。此工具既可以在OpenClaw内部使用,也可作为独立的CLI工具使用。

When to use this skill

适用场景

  • User asks to "截图发给我" (send me a screenshot)
  • User wants to share any image file through Feishu
  • Need to send visual content (charts, diagrams, photos) via Feishu
  • OpenClaw's built-in message tool fails to send images
  • 用户要求“截图发给我”
  • 用户想要通过飞书分享任何图片文件
  • 需要通过飞书发送视觉内容(图表、示意图、照片)
  • OpenClaw内置的消息工具无法发送图片

Configuration

配置说明

For OpenClaw Users

针对OpenClaw用户

When running inside OpenClaw, this skill automatically reads credentials from OpenClaw's Feishu configuration. No manual setup required.
在OpenClaw中运行时,此工具会自动从OpenClaw的飞书配置中读取凭证,无需手动设置。

For Standalone Usage

独立使用

Set the following environment variables:
bash
export FEISHU_APP_ID="cli_xxxxxxxxxxxxxxxx"
export FEISHU_APP_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Or create a
.env
file in your project root:
FEISHU_APP_ID=cli_xxxxxxxxxxxxxxxx
FEISHU_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Note: If running outside OpenClaw without credentials configured, this skill will display a clear error message with setup instructions.
设置以下环境变量:
bash
export FEISHU_APP_ID="cli_xxxxxxxxxxxxxxxx"
export FEISHU_APP_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
或在项目根目录创建
.env
文件:
FEISHU_APP_ID=cli_xxxxxxxxxxxxxxxx
FEISHU_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
注意:如果在OpenClaw外部运行且未配置凭证,此工具会显示清晰的错误消息及设置说明。

Feishu App Setup

飞书应用设置

  1. Go to Feishu Developer Console
  2. Create a new app (Enterprise self-built app)
  3. Enable the following permissions:
    • im:resource
      - Upload images
    • im:message
      - Send messages
  4. Get your App ID and App Secret from the app credentials page
  5. Publish the app and make it available to your organization
  1. 访问飞书开发者控制台
  2. 创建新应用(企业自建应用)
  3. 启用以下权限:
    • im:resource
      - 上传图片
    • im:message
      - 发送消息
  4. 从应用凭证页面获取App ID和App Secret
  5. 发布应用并使其在组织内可用

Usage

使用方法

As a Skill in OpenClaw

在OpenClaw中作为工具使用

The skill will automatically use OpenClaw's Feishu configuration:
javascript
// Example: User asks to "send me a screenshot"
// The skill will automatically:
// 1. Read OpenClaw config for Feishu credentials
// 2. Upload the screenshot to Feishu
// 3. Send it to the user
该工具会自动使用OpenClaw的飞书配置:
javascript
// 示例:用户要求“send me a screenshot”
// 工具会自动执行:
// 1. 读取OpenClaw的飞书配置凭证
// 2. 将截图上传至飞书
// 3. 发送给用户

As a CLI Tool

作为CLI工具使用

Send an image to a Feishu user:
bash
node feishu-image.js --image /path/to/screenshot.png --to ou_xxxxxxxx
With an optional message:
bash
node feishu-image.js --image chart.png --to ou_xxxxxxxx --text "Q4 Sales Report"
Send to a chat group:
bash
node feishu-image.js --image announcement.png --to oc_xxxxxxxx --chat
向飞书用户发送图片:
bash
node feishu-image.js --image /path/to/screenshot.png --to ou_xxxxxxxx
附带可选消息:
bash
node feishu-image.js --image chart.png --to ou_xxxxxxxx --text "Q4 Sales Report"
发送至聊天群组:
bash
node feishu-image.js --image announcement.png --to oc_xxxxxxxx --chat

As a Node.js Library

作为Node.js库使用

javascript
const { FeishuImage } = require('./scripts/feishu-image.js');

const sender = new FeishuImage({
  appId: 'cli_xxxxxxxxxxxxxxxx',
  appSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
});

// Send image to a user
await sender.sendImage({
  imagePath: '/path/to/screenshot.png',
  receiveId: 'ou_xxxxxxxx',
  receiveType: 'user'
});

// Send image with text
await sender.sendImage({
  imagePath: '/path/to/chart.png',
  receiveId: 'ou_xxxxxxxx',
  receiveType: 'user',
  text: 'Here is the sales report'
});
javascript
const { FeishuImage } = require('./scripts/feishu-image.js');

const sender = new FeishuImage({
  appId: 'cli_xxxxxxxxxxxxxxxx',
  appSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
});

// 向用户发送图片
await sender.sendImage({
  imagePath: '/path/to/screenshot.png',
  receiveId: 'ou_xxxxxxxx',
  receiveType: 'user'
});

// 发送带文字的图片
await sender.sendImage({
  imagePath: '/path/to/chart.png',
  receiveId: 'ou_xxxxxxxx',
  receiveType: 'user',
  text: 'Here is the sales report'
});

CLI Reference

CLI 参考

Options

选项

OptionShortDescriptionRequired
--image
-i
Path to the image fileYes
--to
-t
Recipient's Feishu open_id or chat_idYes
--text
Optional text message to includeNo
--chat
-c
Send to a chat group (default: user)No
--help
-h
Show help messageNo
选项缩写说明是否必填
--image
-i
图片文件路径
--to
-t
收件人的飞书open_id或chat_id
--text
可选的附带文字消息
--chat
-c
发送至聊天群组(默认:用户)
--help
-h
显示帮助信息

Examples

示例

bash
undefined
bash
undefined

Basic usage

基础用法

node feishu-image.js -i screenshot.png -t ou_123456
node feishu-image.js -i screenshot.png -t ou_123456

With message

附带消息

node feishu-image.js --image chart.png --to ou_123456 --text "Q4 Report"
node feishu-image.js --image chart.png --to ou_123456 --text "Q4 Report"

To group chat

发送至群组

node feishu-image.js -i announcement.png -t oc_789012 --chat
undefined
node feishu-image.js -i announcement.png -t oc_789012 --chat
undefined

Library API Reference

库API参考

new FeishuImage(config)

new FeishuImage(config)

Creates a new Feishu Image sender instance.
Parameters:
  • config.appId
    (string): Feishu app ID
  • config.appSecret
    (string): Feishu app secret
  • config.baseUrl
    (string, optional): API base URL, defaults to 'https://open.feishu.cn/open-apis'
Example:
javascript
const sender = new FeishuImage({
  appId: process.env.FEISHU_APP_ID,
  appSecret: process.env.FEISHU_APP_SECRET
});
创建一个新的飞书图片发送实例。
参数:
  • config.appId
    (字符串): 飞书应用ID
  • config.appSecret
    (字符串): 飞书应用密钥
  • config.baseUrl
    (字符串,可选): API基础URL,默认值为'https://open.feishu.cn/open-apis'
示例:
javascript
const sender = new FeishuImage({
  appId: process.env.FEISHU_APP_ID,
  appSecret: process.env.FEISHU_APP_SECRET
});

async sendImage(options)

async sendImage(options)

Uploads an image and sends it to a Feishu conversation.
Parameters:
  • options.imagePath
    (string, required): Path to the local image file
  • options.receiveId
    (string, required): Recipient's open_id (for users) or chat_id (for groups)
  • options.receiveType
    (string, optional): 'user' or 'chat', defaults to 'user'
  • options.text
    (string, optional): Optional text message to send with the image
Returns: Promise<string> - The ID of the sent message
Throws:
  • FeishuImageError
    - Various error codes: MISSING_CREDENTIALS, AUTH_FAILED, FILE_NOT_FOUND, UPLOAD_FAILED, SEND_FAILED
Example:
javascript
try {
  const messageId = await sender.sendImage({
    imagePath: '/path/to/screenshot.png',
    receiveId: 'ou_xxxxxxxx',
    receiveType: 'user',
    text: 'Here is the screenshot you requested'
  });
  console.log('Image sent successfully, message ID:', messageId);
} catch (error) {
  console.error('Failed to send image:', error.message);
}
上传图片并发送至飞书会话。
参数:
  • options.imagePath
    (字符串,必填): 本地图片文件路径
  • options.receiveId
    (字符串,必填): 收件人的open_id(用户)或chat_id(群组)
  • options.receiveType
    (字符串,可选): 'user'或'chat',默认值为'user'
  • options.text
    (字符串,可选): 可选的附带文字消息
返回值: Promise<string> - 已发送消息的ID
抛出异常:
  • FeishuImageError
    - 包含多种错误码:MISSING_CREDENTIALS, AUTH_FAILED, FILE_NOT_FOUND, UPLOAD_FAILED, SEND_FAILED
示例:
javascript
try {
  const messageId = await sender.sendImage({
    imagePath: '/path/to/screenshot.png',
    receiveId: 'ou_xxxxxxxx',
    receiveType: 'user',
    text: 'Here is the screenshot you requested'
  });
  console.log('Image sent successfully, message ID:', messageId);
} catch (error) {
  console.error('Failed to send image:', error.message);
}

Error Handling

错误处理

All errors are instances of
FeishuImageError
with specific error codes:
Error CodeDescriptionSolution
MISSING_CREDENTIALS
FEISHU_APP_ID or FEISHU_APP_SECRET not setSet environment variables or pass to constructor
AUTH_FAILED
Authentication with Feishu API failedCheck app_id and app_secret are correct
FILE_NOT_FOUND
Image file does not existCheck the image path is correct
UPLOAD_FAILED
Image upload to Feishu failedCheck network connection and file size limits
SEND_FAILED
Message sending failedCheck recipient ID and permissions
Example error handling:
javascript
const { FeishuImage, FeishuImageError } = require('./scripts/feishu-image.js');

try {
  await sender.sendImage({ ... });
} catch (error) {
  if (error instanceof FeishuImageError) {
    switch (error.code) {
      case 'MISSING_CREDENTIALS':
        console.error('Please set FEISHU_APP_ID and FEISHU_APP_SECRET');
        break;
      case 'AUTH_FAILED':
        console.error('Invalid credentials. Check your app ID and secret.');
        break;
      case 'FILE_NOT_FOUND':
        console.error(`Image file not found: ${error.details.path}`);
        break;
      default:
        console.error(`Error: ${error.message}`);
    }
  } else {
    console.error('Unexpected error:', error);
  }
}
所有错误均为
FeishuImageError
实例,并带有特定错误码:
错误码说明解决方案
MISSING_CREDENTIALS
FEISHU_APP_ID或FEISHU_APP_SECRET未设置设置环境变量或传入构造函数
AUTH_FAILED
飞书API认证失败检查app_id和app_secret是否正确
FILE_NOT_FOUND
图片文件不存在检查图片路径是否正确
UPLOAD_FAILED
图片上传至飞书失败检查网络连接和文件大小限制
SEND_FAILED
消息发送失败检查收件人ID和权限
错误处理示例:
javascript
const { FeishuImage, FeishuImageError } = require('./scripts/feishu-image.js');

try {
  await sender.sendImage({ ... });
} catch (error) {
  if (error instanceof FeishuImageError) {
    switch (error.code) {
      case 'MISSING_CREDENTIALS':
        console.error('Please set FEISHU_APP_ID and FEISHU_APP_SECRET');
        break;
      case 'AUTH_FAILED':
        console.error('Invalid credentials. Check your app ID and secret.');
        break;
      case 'FILE_NOT_FOUND':
        console.error(`Image file not found: ${error.details.path}`);
        break;
      default:
        console.error(`Error: ${error.message}`);
    }
  } else {
    console.error('Unexpected error:', error);
  }
}

Limitations

限制说明

  • Image size: Subject to Feishu API limits (check Feishu documentation for current limits)
  • Supported formats: PNG, JPG, GIF (as supported by Feishu)
  • Rate limiting: Subject to Feishu API rate limits
  • 图片大小:受飞书API限制(请查阅飞书文档获取当前限制)
  • 支持格式:PNG、JPG、GIF(飞书支持的格式)
  • 速率限制:受飞书API速率限制

See Also

相关链接