Restored from v0.2.4: - notifiers/: 14 push channels (bark/serverchan/telegram/lark/webhook/wechat/discord/smtp/...) - push-user.service.ts: multi-user push config linked to cloud_configs.promotion_account - notification.service.ts: full dispatcher with per-config + global fallback New integrations: - cloud.service.ts: notifyConfigEvent on save_success/cookie_expire/save_fail - admin.routes.ts: 7 new API endpoints for push users, notify providers, channel test - database.ts: migration for cloud_configs.notify_config column How it works: - Configure push channels in /admin/system-configs (global_notify_config JSON) - Or per-cloud: link push_users.account = cloud_configs.promotion_account - Notify events: save_success (green), cookie_expire (red), save_fail >=3 consecutive (yellow)
40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.types';
|
|
|
|
const params: NotifierParam[] = [
|
|
{ key: 'token', label: 'Bot Token', type: 'password', required: true, placeholder: '123456:ABC-def' },
|
|
{ key: 'chat_id', label: 'Chat ID', type: 'text', required: true, placeholder: '@频道 或 -1001234567890' },
|
|
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
|
|
{ key: 'content', label: '内容', type: 'text', required: true },
|
|
{ key: 'level', label: '级别', type: 'text', default: 'info', required: false },
|
|
];
|
|
|
|
export const telegramNotifier: Notifier = {
|
|
name: 'telegram',
|
|
label: 'Telegram',
|
|
params,
|
|
async notify(params) {
|
|
try {
|
|
const iconMap = { error: '\ud83d\udea8', warn: '\u26a0\ufe0f', info: '\u2139\ufe0f' };
|
|
const level = params.level || 'info';
|
|
const text = `${iconMap[level] || iconMap.info} *${params.title || 'CloudSearch'}*\n\n${params.content || ''}`;
|
|
const resp = await fetch(`https://api.telegram.org/bot${params.token}/sendMessage`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
chat_id: params.chat_id,
|
|
text,
|
|
parse_mode: 'Markdown',
|
|
disable_web_page_preview: true,
|
|
}),
|
|
});
|
|
const data: any = await resp.json();
|
|
if (data.ok)
|
|
return { success: true, message: 'Telegram 推送成功' };
|
|
return { success: false, message: data.description || `HTTP ${resp.status}` };
|
|
}
|
|
catch (err: any) {
|
|
return { success: false, message: err.message };
|
|
}
|
|
},
|
|
};
|