这是一个用于与 FeiShu(飞书)集成的工具包,支持多种功能模块开发,能帮助开发者更便捷地与飞书进行交互。
此工具包能让你轻松实现与飞书的集成,下面为你介绍安装和基本使用方法。
npm install @feishu/abc123
import { FeiShuClient } from '@feishu/core';
const config: ClientConfig = {
appId: 'your_app_id',
appSecret: 'your_app_secret'
};
const client = new FeiShuClient(config);
await client.sendMessage('open_chat_id', 'hello world');
const card = {
type: 'message_card',
content: [{
type: 'text',
text: '卡片内容'
}]
};
await client.sendCardMessage('open_chat_id', card);
所有 API 请求错误将通过 FeiShuApiError 类进行包装:
try {
// 执行 API 操作
} catch (error) {
if (error instanceof FeiShuApiError) {
// 处理特定的 API 错误
console.error(`飞书 API 错误 (${error.code}): ${error.message}`);
} else {
// 处理通用错误
console.error('意外错误:', error);
}
// 转换为用户友好的消息
throw new FeiShuApiError('操作失败', { cause: error });
}
请参考错误处理文档:错误处理指南
src/client/feature/ 目录下创建新客户端类:// src/client/feature/feature-client.ts
export class FeatureClient extends ApiClient {
async getFeatureData(id: string): Promise<FeatureData> {
return this.request<FeatureResponse>('/feature/get', { id });
}
}
src/services/feature/ 目录下创建新服务类:// src/services/feature/feature-service.ts
export class FeatureService {
private client: FeatureClient;
constructor(config: ApiClientConfig) {
this.client = new FeatureClient(config);
}
async getFeature(id: string): Promise<Feature> {
try {
const data = await this.client.getFeatureData(id);
return this.transformData(data);
} catch (error) {
handleError(error);
}
}
}
src/services/index.ts 中导出新服务:// src/services/index.ts
export { FeatureService } from './feature/feature-service';
src/server/tools/feature-tools.ts 中创建工具函数:// src/server/tools/feature-tools.ts
export function createFeatureTool() {
return {
getFeature: async (id: string) => {
const service = new FeatureService({ /* 配置 */ });
return await service.getFeature(id);
}
};
}
import { createFeatureTool } from './tools/feature-tools';
const tool = createFeatureTool();
await tool.getFeature('123');
请遵循以下提交规范:
src/components/ 下创建新组件project/
├── src/
│ ├── client/
│ │ └── feature/
│ │ └── feature-client.ts
│ └── services/
│ └── feature/
│ └── feature-service.ts
└── tools/
└── feature-tools.ts
本项目遵循 MIT 协议。