refactor: centralize wechat notification dispatch
This commit is contained in:
@@ -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;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user