refactor: centralize wechat notification dispatch

This commit is contained in:
john
2026-06-30 21:26:46 +08:00
parent 9c653e9b16
commit 6e4e0e2937
6 changed files with 186 additions and 12 deletions
+30
View File
@@ -0,0 +1,30 @@
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;
},
};
}