openclaw/src/web/auto-reply/monitor/peer.ts
Nick Sullivan e629254b26 fix(whatsapp): normalize reaction peer IDs to match message routing
Reactions now use the same peer ID normalization as messages (E.164
format for DMs) to ensure they land in the correct session key. Without
this fix, per-peer DM scopes would route reactions to a JID-based session
while messages go to an E.164-based session, making reactions invisible
to the agent.

- Add resolveReactionPeerId() matching resolvePeerId() logic
- Apply E.164 normalization for DM reactions when senderE164 available
- Add test verifying reactions land in the same session as messages
- Fixes session routing mismatch caught by Codex review

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 10:44:00 -06:00

18 lines
882 B
TypeScript

import { jidToE164, normalizeE164 } from "../../../utils.js";
import type { WebInboundMsg } from "../types.js";
import type { WebInboundReaction } from "../../inbound/types.js";
export function resolvePeerId(msg: WebInboundMsg) {
if (msg.chatType === "group") return msg.conversationId ?? msg.from;
if (msg.senderE164) return normalizeE164(msg.senderE164) ?? msg.senderE164;
if (msg.from.includes("@")) return jidToE164(msg.from) ?? msg.from;
return normalizeE164(msg.from) ?? msg.from;
}
export function resolveReactionPeerId(reaction: WebInboundReaction) {
if (reaction.chatType === "group") return reaction.chatJid;
if (reaction.senderE164) return normalizeE164(reaction.senderE164) ?? reaction.senderE164;
if (reaction.chatJid.includes("@")) return jidToE164(reaction.chatJid) ?? reaction.chatJid;
return normalizeE164(reaction.chatJid) ?? reaction.chatJid;
}