安装命令
openclawmp install plugin/@u-edee49565d614631bad5/feishu-toolkit标签
#feishu#lark#toolkit#nodejs#cli#document#message#chat
README
飞书工具库
一个功能完整的飞书开放平台工具库,支持文档操作和消息管理。
✨ 同时支持 Lark(国际版)和飞书(中国版)
功能特性
📄 文档工具
- 读取飞书文档内容
- 创建新的飞书文档
- 支持 Markdown 转飞书文档
- 参考模板格式创建文档
💬 消息工具
- 发送文本/富文本/文件消息
- 消息回复功能
- 群聊管理(列表、查找、信息获取)
- 文件上传
🌍 多区域支持
- Lark(国际版):
open.larksuite.com - 飞书(中国版):
open.feishu.cn
项目结构
feishu-doc-helper/
├── lib/ # 核心库
│ ├── common/ # 通用模块
│ │ └── auth.js # 认证模块
│ ├── message/ # 消息工具
│ │ ├── message.js # 消息发送
│ │ └── chat.js # 群聊管理
│ ├── doc/ # 文档工具(待实现)
│ └── index.js # 入口文件
├── cli/ # 命令行工具
│ ├── list-chats.js # 列出群聊
│ └── send-message.js # 发送消息
├── scripts/ # 原始脚本(兼容)
│ ├── lark-doc-reader.js
│ ├── lark-doc-writer-v3.js
│ └── ...
├── templates/ # 消息模板
├── .lark-config.json # 配置文件
└── README.md
快速开始
1. 配置飞书应用
在飞书开放平台创建应用,获取:
APP_ID:应用 IDAPP_SECRET:应用密钥
确保应用有以下权限:
im:message- 消息发送im:chat- 群聊管理docx:document- 文档读写
2. 配置 token
创建 .lark-config.json 文件:
{
"app_id": "cli_xxxxx",
"app_secret": "xxxxx",
"region": "lark"
}
region 参数说明:
"lark":Lark 国际版(默认)"feishu":飞书中国版
注意: 不同区域需要在对应平台创建应用:
3. 安装依赖
npm install form-data
使用方式
作为库使用
const { LarkAuth, LarkMessage, LarkChat } = require('./lib');
// 初始化
const auth = LarkAuth.fromConfig('.lark-config.json');
const message = new LarkMessage(auth);
const chat = new LarkChat(auth);
// 列出群聊
const chats = await chat.list();
// 查找群聊
const targetChat = await chat.findByName('测试');
// 发送文本消息
await message.sendText(targetChat.chat_id, 'Hello World');
// 发送富文本消息
await message.sendRichText(chatId, {
zh_cn: {
title: '标题',
content: [
[{ tag: 'text', text: '内容' }]
]
}
});
// 上传并发送文件
const fileData = await message.uploadFile('./file.zip');
await message.sendFile(chatId, fileData.file_key);
// 回复消息
await message.reply(messageId, JSON.stringify({ text: '回复内容' }), 'text');
使用 CLI 工具
# 列出所有群聊
node cli/list-chats.js
# 发送消息
node cli/send-message.js "测试" "Hello World"
API 文档
LarkAuth
认证模块,管理 access_token。
// 从配置文件创建
const auth = LarkAuth.fromConfig('.lark-config.json');
// 手动创建
const auth = new LarkAuth(APP_ID, APP_SECRET);
// 获取 token(自动缓存)
const token = await auth.getTenantAccessToken();
LarkMessage
消息发送模块。
const message = new LarkMessage(auth);
// 发送文本消息
await message.sendText(chatId, text);
// 发送富文本消息
await message.sendRichText(chatId, content);
// 发送文件消息
await message.sendFile(chatId, fileKey);
// 回复消息
await message.reply(messageId, content, msgType);
// 上传文件
const fileData = await message.uploadFile(filePath);
LarkChat
群聊管理模块。
const chat = new LarkChat(auth);
// 列出所有群聊
const chats = await chat.list();
// 根据名称查找群聊
const targetChat = await chat.findByName('测试');
// 获取群聊信息
const info = await chat.getInfo(chatId);
实际应用
发送项目简报
const auth = LarkAuth.fromConfig('.lark-config.json');
const message = new LarkMessage(auth);
const chat = new LarkChat(auth);
// 查找目标群聊
const targetChat = await chat.findByName('AI分享群');
// 构建富文本内容
const content = {
zh_cn: {
title: '🚀 项目更新',
content: [
[{ tag: 'text', text: '新功能已上线' }]
]
}
};
// 发送消息
const result = await message.sendRichText(targetChat.chat_id, content);
// 上传并回复文件
const fileData = await message.uploadFile('./package.zip');
await message.reply(result.message_id, JSON.stringify({ file_key: fileData.file_key }), 'file');
开发计划
- 消息工具基础功能
- 群聊管理
- 文件上传
- 消息回复
- 文档工具模块化
- 消息模板系统
- 批量操作支持
- TypeScript 支持
- 单元测试
许可证
MIT License
相关推荐
yahoo-finance-pluginv1.0.0
接入 Yahoo Finance API 的金融数据插件
Brave搜索v1.0.1
通过Brave Search API进行网络搜索和内容提取,用于搜索文档、事实或任何网络内容,轻量级且无需浏览器。
精英长期记忆v1.2.3
为 Cursor、Claude、ChatGPT 和 Copilot 提供的终极 AI 代理记忆系统。采用 WAL 协议 + 向量搜索 + git-notes + 云备份。再也不丢失上下文。Vibe-coding 就绪。
GitHub API Pluginv1.0.0
GitHub REST API 插件,提供 repositories, issues, pull requests, commits 的查询与操作工具。