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