31 lines
895 B
JavaScript
31 lines
895 B
JavaScript
export function createNotificationDispatcher({ sendWechatTextToUser, logger = console } = {}) {
|
|
const sendWechat = async (userId, text) => {
|
|
if (typeof sendWechatTextToUser !== 'function') return false;
|
|
await sendWechatTextToUser(userId, text);
|
|
return true;
|
|
};
|
|
|
|
return {
|
|
async sendRechargeSuccess({ userId, title, body, dedupeKey = null }) {
|
|
const sent = await sendWechat(userId, `${title}\n${body}`.trim());
|
|
logger.info?.('Notification dispatch:', {
|
|
type: 'recharge_success',
|
|
userId,
|
|
dedupeKey,
|
|
sent,
|
|
});
|
|
return sent;
|
|
},
|
|
async sendScheduleNotification({ userId, text }) {
|
|
const sent = await sendWechat(userId, text);
|
|
logger.info?.('Notification dispatch:', {
|
|
type: 'schedule_notification',
|
|
userId,
|
|
dedupeKey: null,
|
|
sent,
|
|
});
|
|
return sent;
|
|
},
|
|
};
|
|
}
|