fix(whatsapp): compare selfLid for reply-to-bot implicit mention in groups

This commit is contained in:
khhjoe
2026-03-25 01:13:16 +08:00
committed by Peter Steinberger
parent ff25407861
commit 93594a1440
3 changed files with 12 additions and 2 deletions

View File

@@ -127,14 +127,19 @@ export function applyGroupGating(params: ApplyGroupGatingParams) {
conversationId: params.conversationId,
});
const requireMention = activation !== "always";
const selfJid = params.msg.selfJid?.replace(/:\\d+/, "");
const replySenderJid = params.msg.replyToSenderJid?.replace(/:\\d+/, "");
const selfJid = params.msg.selfJid?.replace(/:\d+/, "");
const selfLid = params.msg.selfLid?.replace(/:\d+/, "");
const replySenderJid = params.msg.replyToSenderJid?.replace(/:\d+/, "");
const selfE164 = params.msg.selfE164 ? normalizeE164(params.msg.selfE164) : null;
const replySenderE164 = params.msg.replyToSenderE164
? normalizeE164(params.msg.replyToSenderE164)
: null;
// Detect reply-to-bot: compare JIDs, LIDs, and E.164 numbers.
// WhatsApp may report the quoted message sender as either a phone JID
// (xxxxx@s.whatsapp.net) or a LID (xxxxx@lid), so we compare both.
const implicitMention = Boolean(
(selfJid && replySenderJid && selfJid === replySenderJid) ||
(selfLid && replySenderJid && selfLid === replySenderJid) ||
(selfE164 && replySenderE164 && selfE164 === replySenderE164),
);
const mentionGate = resolveMentionGating({

View File

@@ -77,6 +77,9 @@ export async function monitorWebInbox(options: {
const selfJid = sock.user?.id;
const selfE164 = selfJid ? jidToE164(selfJid) : null;
// Bot's own LID (Linked Identity) — needed for reply-to-bot detection
// when contextInfo.participant returns a LID instead of a phone JID.
const selfLid = (sock.user as { lid?: string } | undefined)?.lid ?? undefined;
const debouncer = createInboundDebouncer<WebInboundMessage>({
debounceMs: options.debounceMs ?? 0,
buildKey: (msg) => {
@@ -416,6 +419,7 @@ export async function monitorWebInbox(options: {
groupParticipants: inbound.groupParticipants,
mentionedJids: mentionedJids ?? undefined,
selfJid,
selfLid,
selfE164,
fromMe: Boolean(msg.key?.fromMe),
location: enriched.location ?? undefined,

View File

@@ -30,6 +30,7 @@ export type WebInboundMessage = {
groupParticipants?: string[];
mentionedJids?: string[];
selfJid?: string | null;
selfLid?: string | null;
selfE164?: string | null;
fromMe?: boolean;
location?: NormalizedLocation;