Files
CloudSearch/source_clean/src/cloud/notifiers/webhook.notifier.ts

31 lines
1.0 KiB
TypeScript

import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.types';
const params: NotifierParam[] = [
{ key: 'url', label: 'Webhook URL', type: 'url', required: true, placeholder: 'https://example.com/webhook' }
];
export const webhookNotifier: Notifier = {
name: 'webhook',
label: '\u81ea\u5b9a\u4e49 Webhook',
params,
async notify(p: NotifyParams): Promise<NotifyResult> {
try {
const resp = await fetch(p.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: p.title || 'CloudSearch',
content: p.content || '',
level: p.level || 'info',
source: 'CloudSearch',
timestamp: new Date().toISOString(),
}),
});
if (resp.ok) return { success: true, message: 'Webhook \u63a8\u9001\u6210\u529f' };
return { success: false, message: `HTTP ${resp.status}` };
} catch (err: any) {
return { success: false, message: err.message };
}
},
};