2baf29b3ae
Deliver encrypted health zone, observation API, baseline maturity pipeline, page-data bindings, and H5/WeChat channel integration for health P0. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
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;
|
|
},
|
|
async sendHealthEventNotification({ userId, title, body, eventId = null, severity = 'alert' }) {
|
|
const text = `${title}\n${body}`.trim();
|
|
const sent = await sendWechat(userId, text);
|
|
logger.info?.('Notification dispatch:', {
|
|
type: 'health_event_notification',
|
|
userId,
|
|
dedupeKey: eventId,
|
|
severity,
|
|
sent,
|
|
});
|
|
return sent;
|
|
},
|
|
};
|
|
}
|