feishu-image
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFeishu 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 file in your project root:
.envFEISHU_APP_ID=cli_xxxxxxxxxxxxxxxx
FEISHU_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxNote: 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"或在项目根目录创建文件:
.envFEISHU_APP_ID=cli_xxxxxxxxxxxxxxxx
FEISHU_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx注意:如果在OpenClaw外部运行且未配置凭证,此工具会显示清晰的错误消息及设置说明。
Feishu App Setup
飞书应用设置
- Go to Feishu Developer Console
- Create a new app (Enterprise self-built app)
- Enable the following permissions:
- - Upload images
im:resource - - Send messages
im:message
- Get your App ID and App Secret from the app credentials page
- Publish the app and make it available to your organization
- 访问飞书开发者控制台
- 创建新应用(企业自建应用)
- 启用以下权限:
- - 上传图片
im:resource - - 发送消息
im:message
- 从应用凭证页面获取App ID和App Secret
- 发布应用并使其在组织内可用
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_xxxxxxxxWith 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 --chatAs 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
选项
| Option | Short | Description | Required |
|---|---|---|---|
| | Path to the image file | Yes |
| | Recipient's Feishu open_id or chat_id | Yes |
| Optional text message to include | No | |
| | Send to a chat group (default: user) | No |
| | Show help message | No |
| 选项 | 缩写 | 说明 | 是否必填 |
|---|---|---|---|
| | 图片文件路径 | 是 |
| | 收件人的飞书open_id或chat_id | 是 |
| 可选的附带文字消息 | 否 | |
| | 发送至聊天群组(默认:用户) | 否 |
| | 显示帮助信息 | 否 |
Examples
示例
bash
undefinedbash
undefinedBasic 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
undefinednode feishu-image.js -i announcement.png -t oc_789012 --chat
undefinedLibrary API Reference
库API参考
new FeishuImage(config)
new FeishuImage(config)new FeishuImage(config)
new FeishuImage(config)Creates a new Feishu Image sender instance.
Parameters:
- (string): Feishu app ID
config.appId - (string): Feishu app secret
config.appSecret - (string, optional): API base URL, defaults to 'https://open.feishu.cn/open-apis'
config.baseUrl
Example:
javascript
const sender = new FeishuImage({
appId: process.env.FEISHU_APP_ID,
appSecret: process.env.FEISHU_APP_SECRET
});创建一个新的飞书图片发送实例。
参数:
- (字符串): 飞书应用ID
config.appId - (字符串): 飞书应用密钥
config.appSecret - (字符串,可选): API基础URL,默认值为'https://open.feishu.cn/open-apis'
config.baseUrl
示例:
javascript
const sender = new FeishuImage({
appId: process.env.FEISHU_APP_ID,
appSecret: process.env.FEISHU_APP_SECRET
});async sendImage(options)
async sendImage(options)async sendImage(options)
async sendImage(options)Uploads an image and sends it to a Feishu conversation.
Parameters:
- (string, required): Path to the local image file
options.imagePath - (string, required): Recipient's open_id (for users) or chat_id (for groups)
options.receiveId - (string, optional): 'user' or 'chat', defaults to 'user'
options.receiveType - (string, optional): Optional text message to send with the image
options.text
Returns: Promise<string> - The ID of the sent message
Throws:
- - Various error codes: MISSING_CREDENTIALS, AUTH_FAILED, FILE_NOT_FOUND, UPLOAD_FAILED, SEND_FAILED
FeishuImageError
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 - (字符串,必填): 收件人的open_id(用户)或chat_id(群组)
options.receiveId - (字符串,可选): 'user'或'chat',默认值为'user'
options.receiveType - (字符串,可选): 可选的附带文字消息
options.text
返回值: Promise<string> - 已发送消息的ID
抛出异常:
- - 包含多种错误码:MISSING_CREDENTIALS, AUTH_FAILED, FILE_NOT_FOUND, UPLOAD_FAILED, SEND_FAILED
FeishuImageError
示例:
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 with specific error codes:
FeishuImageError| Error Code | Description | Solution |
|---|---|---|
| FEISHU_APP_ID or FEISHU_APP_SECRET not set | Set environment variables or pass to constructor |
| Authentication with Feishu API failed | Check app_id and app_secret are correct |
| Image file does not exist | Check the image path is correct |
| Image upload to Feishu failed | Check network connection and file size limits |
| Message sending failed | Check 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| 错误码 | 说明 | 解决方案 |
|---|---|---|
| FEISHU_APP_ID或FEISHU_APP_SECRET未设置 | 设置环境变量或传入构造函数 |
| 飞书API认证失败 | 检查app_id和app_secret是否正确 |
| 图片文件不存在 | 检查图片路径是否正确 |
| 图片上传至飞书失败 | 检查网络连接和文件大小限制 |
| 消息发送失败 | 检查收件人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速率限制