feat: add Feishu notifier for message notifications
- Implemented a lightweight notification library with support for multiple channels. - Added FeishuNotifier class to send messages via Feishu webhook. - Created README documentation for usage and configuration of Feishu notifier. - Added TypeScript configuration for the project. - Included a test script for verifying Feishu message notifications.
This commit is contained in:
34
src/notiify/feishu.ts
Normal file
34
src/notiify/feishu.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Notification } from '../core/index.ts';
|
||||
|
||||
interface FeishuConfig {
|
||||
webhook: string;
|
||||
}
|
||||
|
||||
export class FeishuNotifier implements Notification {
|
||||
private webhook: string;
|
||||
|
||||
constructor(config: FeishuConfig) {
|
||||
this.webhook = config.webhook;
|
||||
}
|
||||
|
||||
async notify(message: string): Promise<void> {
|
||||
const payload = {
|
||||
msg_type: 'text',
|
||||
content: {
|
||||
text: message,
|
||||
},
|
||||
};
|
||||
|
||||
const response = await fetch(this.webhook, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`飞书推送失败: ${response.statusText}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user