Expose resolveSessionPeer on ctx.dshIm for ops schedulers (ops.23).

WhatsApp registers a peer resolver so cron_create can default IM delivery to the calling session's bot/target.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-05 21:48:00 +08:00
parent 6d2229acd2
commit 41f13bb90c
3 changed files with 42 additions and 2 deletions

View file

@ -17,7 +17,20 @@ export async function apply(ctx, config = {}) {
config.rpcOptions,
config.rpcAuthority,
);
let unregisterPeer = () => {};
try {
const dshIm = typeof ctx.get === 'function' ? ctx.get('dshIm') : undefined;
if (dshIm && typeof dshIm.registerPeerResolver === 'function'
&& typeof production.controller?.resolveChannelPeer === 'function') {
unregisterPeer = dshIm.registerPeerResolver((sessionId) => (
production.controller.resolveChannelPeer(sessionId)
));
}
} catch {
// dshIm optional during partial boots
}
ctx.effect(() => async () => {
unregisterPeer?.();
await unregisterDelivery?.();
await production.close();
}, 'dsh-im: close WhatsApp Web connections');