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
+9 -4
View File
@@ -21,6 +21,7 @@ import { createPlazaInteractionService } from './plaza-interactions.mjs';
import { createPlazaOpsService } from './plaza-ops.mjs';
import { createNoopPlazaRedis } from './plaza-redis.mjs';
import { ensureAlgorithmConfig, loadAlgorithmConfig } from './plaza-algorithm.mjs';
import { createNotificationDispatcher } from './notification-dispatcher.mjs';
import { createWechatAdminService } from './wechat-admin.mjs';
import { createWechatMpService, loadWechatMpConfig } from './wechat-mp.mjs';
@@ -98,16 +99,20 @@ export async function createAdminServices(env = {}) {
throw new Error('admin bootstrap does not proxy WeChat chat sessions');
},
});
userAuth.setRechargeNotifier(async ({ userId, title, body }) => {
if (!wechatMpService?.enabled) return;
await wechatMpService.sendTextToUser(userId, `${title}\n${body}`.trim());
const notificationDispatcher = createNotificationDispatcher({
sendWechatTextToUser: wechatMpService?.enabled
? (userId, text) => wechatMpService.sendTextToUser(userId, text)
: null,
});
userAuth.setRechargeNotifier(async ({ userId, title, body, dedupeKey }) => {
await notificationDispatcher.sendRechargeSuccess({ userId, title, body, dedupeKey });
});
const wechatAdmin = createWechatAdminService(pool, {
config: wechatMpConfig,
scheduleEnabled: process.env.H5_SCHEDULE_ENABLED === '1',
reminderWorkerEnabled: process.env.H5_REMINDER_WORKER_ENABLED === '1',
sendWechatTextToUser: wechatMpService?.enabled
? (userId, text) => wechatMpService.sendTextToUser(userId, text)
? (userId, text) => notificationDispatcher.sendScheduleNotification({ userId, text })
: null,
});