import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.types';

const params: NotifierParam[] = [
{ key: 'webhook_url', label: 'Webhook URL', type: 'url', required: true, placeholder: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx' },
    
];

export const wechatWorkBotNotifier: Notifier = {
name: 'wechat_work_bot',
    label: '企业微信机器人',
    params,
    async notify(params) {
        try {
            const content = `## ${params.title || 'CloudSearch'}\n${params.content || ''}`;
            const resp = await fetch(params.webhook_url, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({
                    msgtype: 'markdown',
                    markdown: { content },
                }),
            });
            const data: any = await resp.json();
            if (data.errcode === 0)
                return { success: true, message: '企业微信推送成功' };
            return { success: false, message: data.errmsg || `HTTP ${resp.status}` };
        }
        catch (err: any) {
            return { success: false, message: err.message };
        }
    },
};
