fix: persist session origin metadata

This commit is contained in:
Peter Steinberger
2026-01-18 03:40:35 +00:00
parent dad69afc84
commit 0d9172d761
13 changed files with 102 additions and 23 deletions

View File

@@ -206,26 +206,15 @@ export async function processMessage(params: {
whatsappInboundLog.debug(`Inbound body: ${elide(combinedBody, 400)}`);
}
if (params.msg.chatType !== "group") {
const to = (() => {
if (params.msg.senderE164) return normalizeE164(params.msg.senderE164);
// In direct chats, `msg.from` is already the canonical conversation id.
if (params.msg.from.includes("@")) return jidToE164(params.msg.from);
return normalizeE164(params.msg.from);
})();
if (to) {
updateLastRouteInBackground({
cfg: params.cfg,
backgroundTasks: params.backgroundTasks,
storeAgentId: params.route.agentId,
sessionKey: params.route.mainSessionKey,
channel: "whatsapp",
to,
accountId: params.route.accountId,
warn: params.replyLogger.warn.bind(params.replyLogger),
});
}
}
const dmRouteTarget =
params.msg.chatType !== "group"
? (() => {
if (params.msg.senderE164) return normalizeE164(params.msg.senderE164);
// In direct chats, `msg.from` is already the canonical conversation id.
if (params.msg.from.includes("@")) return jidToE164(params.msg.from);
return normalizeE164(params.msg.from);
})()
: undefined;
const textLimit = params.maxMediaTextChunkLimit ?? resolveTextChunkLimit(params.cfg, "whatsapp");
let didLogHeartbeatStrip = false;
@@ -285,6 +274,20 @@ export async function processMessage(params: {
OriginatingTo: params.msg.from,
});
if (dmRouteTarget) {
updateLastRouteInBackground({
cfg: params.cfg,
backgroundTasks: params.backgroundTasks,
storeAgentId: params.route.agentId,
sessionKey: params.route.mainSessionKey,
channel: "whatsapp",
to: dmRouteTarget,
accountId: params.route.accountId,
ctx: ctxPayload,
warn: params.replyLogger.warn.bind(params.replyLogger),
});
}
const storePath = resolveStorePath(params.cfg.session?.store, {
agentId: params.route.agentId,
});