function resolveWechatDispatchSent(result) { if (result && typeof result === 'object') { return result.sent !== false && !result.deferred && !result.skipped; } return result !== false; } export function createNotificationDispatcher({ sendWechatTextToUser, logger = console } = {}) { const sendWechat = async (userId, text, options = {}) => { if (typeof sendWechatTextToUser !== 'function') return false; const result = await sendWechatTextToUser(userId, text, options); return resolveWechatDispatchSent(result); }; 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, verifiedHtmlUrls = [] }) { const sent = await sendWechat(userId, text, { verifiedHtmlUrls }); logger.info?.('Notification dispatch:', { type: 'schedule_notification', userId, dedupeKey: null, sent, verifiedHtmlCount: verifiedHtmlUrls.length, }); return sent; }, }; }