feishu-bot-message-wrapper
v1.0.1
Published
一个简单快速的飞书消息发送命令行工具,基于飞书官方SDK构建
Maintainers
Readme
飞书消息发送工具
一个简单快速的飞书消息发送命令行工具,基于 @larksuiteoapi/node-sdk 和 commander.js 构建。
✨ 特性
- 🚀 简单易用 - 支持多种配置方式(命令行参数、环境变量、配置文件)
- 📨 多种消息类型 - 支持文本、富文本、图片、文件、音频、视频、表情包、卡片等消息类型
- 🎴 卡片模板 - 支持飞书官方卡片模板功能
- 🔄 消息去重 - 支持 UUID 去重,防止重复发送
- 🛡️ 智能验证 - 完整的参数验证和错误处理
- 📚 丰富的帮助 - 基于 commander.js 的详细帮助信息
🚀 快速开始
1. 安装依赖
bun install2. 配置认证信息
方式一:环境变量
export FEISHU_APP_ID="your_app_id"
export FEISHU_APP_SECRET="your_app_secret"
export FEISHU_RECEIVE_ID="your_receive_id"方式二:配置文件
创建 ~/.config/feishu-bot-config.json:
{
"appId": "your_app_id",
"appSecret": "your_app_secret",
"receiveId": "your_receive_id",
"receiveIdType": "open_id"
}3. 发送消息
# 发送文本消息
bun run index.ts --message "Hello World"
# 发送富文本消息
bun run index.ts --message-type post --message "富文本消息"
# 指定接收者
bun run index.ts --message "Hello" --receive-id "ou_xxx"📋 支持的消息类型
text- 文本消息post- 富文本消息image- 图片消息file- 文件消息audio- 语音消息media- 视频消息sticker- 表情包消息interactive- 卡片消息share_chat- 分享群名片share_user- 分享个人名片system- 系统消息
🛠️ 使用指南
基本用法
# 查看帮助信息
bun run index.ts --help
# 查看版本信息
bun run index.ts --version
# 发送文本消息
bun run index.ts --message "这是一条测试消息"
# 发送富文本消息
bun run index.ts --message-type post --message "这是一条富文本消息"
# 发送卡片消息
bun run index.ts --message-type interactive --message "这是一条卡片消息"
# 指定接收者ID类型
bun run index.ts --receive-id-type "chat_id" --message "群聊消息"高级功能
卡片模板消息
# 使用模板发送消息
bun run index.ts \
--template-id "your_template_id" \
--template-variable '{"title":"标题","content":"内容"}' \
--receive-id "ou_xxx"消息去重
# 使用UUID防止重复发送
bun run index.ts \
--message "重要消息" \
--uuid "unique-identifier" \
--receive-id "ou_xxx"完整参数示例
bun run index.ts \
--app-id "your_app_id" \
--app-secret "your_app_secret" \
--receive-id "your_receive_id" \
--receive-id-type "open_id" \
--message "Hello World" \
--message-type "text" \
--config "./config.json" \
--uuid "unique-identifier"⚙️ 配置方式
工具支持三种配置方式,优先级从高到低:
- 命令行参数 - 最高优先级
- 环境变量 - 中等优先级
- 配置文件 - 最低优先级
环境变量列表
FEISHU_APP_ID- 飞书应用IDFEISHU_APP_SECRET- 飞书应用SecretFEISHU_RECEIVE_ID- 接收者IDFEISHU_RECEIVE_ID_TYPE- 接收者ID类型
配置文件格式
默认配置文件路径:~/.config/feishu-bot-config.json
{
"appId": "your_app_id",
"appSecret": "your_app_secret",
"receiveId": "your_receive_id",
"receiveIdType": "open_id"
}🎯 命令行选项
基于 commander.js 提供丰富的命令行选项:
Options:
--app-id <id> 飞书应用ID
--app-secret <secret> 飞书应用Secret
--receive-id <id> 接收者ID
--receive-id-type <type> 接收者ID类型 (open_id, union_id, user_id, email, chat_id)
--message <text> 消息内容
--message-type <type> 消息类型
--config <path> 配置文件路径
--uuid <uuid> 消息去重标识符
--template-id <id> 消息卡片模板ID
--template-variable <json> 模板变量JSON
-h, --help 显示帮助信息
-V, --version 显示版本信息📦 依赖项
@larksuiteoapi/node-sdk- 飞书官方SDKcommander.js- 命令行界面框架bun- JavaScript 运行时和包管理器
🔧 开发
项目结构
feishu_bot_message_wrapper/
├── index.ts # 主程序入口
├── package.json # 项目配置
├── README.md # 项目说明
├── USAGE.md # 使用指南
├── FIX_REPORT.md # 修复报告
└── CLAUDE.md # Claude 配置运行脚本
# 启动开发服务器
bun run start
# 构建项目
bun run build
# 运行测试
bun run test🧪 测试
确保配置正确的环境变量后,可以运行以下命令测试:
# 测试文本消息
bun run index.ts --message "测试消息"
# 测试富文本消息
bun run index.ts --message-type post --message "富文本测试"
# 测试卡片消息
bun run index.ts --message-type interactive --message "卡片测试"📚 官方文档
🤝 贡献
欢迎提交 Issue 和 Pull Request!
📄 许可证
MIT License
注意:使用前请确保已在飞书开放平台创建应用并获取相应的 App ID 和 App Secret。
