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

33 lines
1.4 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerNotificationHandler = registerNotificationHandler;
exports.getNotificationHandler = getNotificationHandler;
exports.registerNotificationFailureHandler = registerNotificationFailureHandler;
exports.getNotificationFailureHandlers = getNotificationFailureHandlers;
const assert_1 = require("oak-domain/lib/utils/assert");
const wechatMp_1 = require("./wechatMp");
const wechatPublic_1 = require("./wechatPublic");
const sms_1 = require("./sms");
const email_1 = require("./email");
const notificationHandlers = {};
const notificationFailureHandlers = [];
function registerNotificationHandler(channel, handler) {
notificationHandlers[channel] = handler;
}
function getNotificationHandler(channel) {
const handler = notificationHandlers[channel];
(0, assert_1.assert)(handler, `通知渠道 ${channel} 的处理器未注册`);
return handler;
}
function registerNotificationFailureHandler(handler) {
notificationFailureHandlers.push(handler);
}
function getNotificationFailureHandlers() {
return notificationFailureHandlers;
}
// 默认注册所有处理器
registerNotificationHandler('wechatMp', wechatMp_1.wechatMpHandler);
registerNotificationHandler('wechatPublic', wechatPublic_1.wechatPublicHandler);
registerNotificationHandler('sms', sms_1.smsHandler);
registerNotificationHandler('email', email_1.emailHandler);