oak-general-business/es/utils/notification/index.js

27 lines
1.0 KiB
JavaScript

import { assert } from "oak-domain/lib/utils/assert";
import { wechatMpHandler } from './wechatMp';
import { wechatPublicHandler } from './wechatPublic';
import { smsHandler } from './sms';
import { emailHandler } from './email';
const notificationHandlers = {};
const notificationFailureHandlers = [];
export function registerNotificationHandler(channel, handler) {
notificationHandlers[channel] = handler;
}
export function getNotificationHandler(channel) {
const handler = notificationHandlers[channel];
assert(handler, `通知渠道 ${channel} 的处理器未注册`);
return handler;
}
export function registerNotificationFailureHandler(handler) {
notificationFailureHandlers.push(handler);
}
export function getNotificationFailureHandlers() {
return notificationFailureHandlers;
}
// 默认注册所有处理器
registerNotificationHandler('wechatMp', wechatMpHandler);
registerNotificationHandler('wechatPublic', wechatPublicHandler);
registerNotificationHandler('sms', smsHandler);
registerNotificationHandler('email', emailHandler);