From 9f96b6146858a56b58bf71bc0b1da5320d45b862 Mon Sep 17 00:00:00 2001 From: moltbot-bot Date: Thu, 29 Jan 2026 17:43:45 -0300 Subject: [PATCH] fix(whatsapp): safe handling for new activation modes (reply/never) and explicit mention gating --- src/web/auto-reply/monitor/group-gating.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/web/auto-reply/monitor/group-gating.ts b/src/web/auto-reply/monitor/group-gating.ts index 44df28fe7..5f2be9e0c 100644 --- a/src/web/auto-reply/monitor/group-gating.ts +++ b/src/web/auto-reply/monitor/group-gating.ts @@ -114,30 +114,34 @@ export function applyGroupGating(params: { (selfE164 && replySenderE164 && selfE164 === replySenderE164), ); + // Ensure safe default for shouldBypassMention in case it's undefined in some contexts + const safeShouldBypassMention = typeof shouldBypassMention !== "undefined" ? shouldBypassMention : false; + // Determine if we should process based on activation mode const shouldProcess = (() => { if (activation === "always") return true; - if (activation === "never") return shouldBypassMention; - if (activation === "replies") return isReplyToBot || shouldBypassMention; + if (activation === "never") return safeShouldBypassMention; + if (activation === "replies") return isReplyToBot || safeShouldBypassMention; if (activation === "mention+replies") - return wasMentioned || isReplyToBot || shouldBypassMention; + return wasMentioned || isReplyToBot || safeShouldBypassMention; // Default to "mention" mode - return wasMentioned || shouldBypassMention; + return wasMentioned || safeShouldBypassMention; })(); - const requireMention = activation !== "always" && activation !== "replies"; + // require mention only in strict 'mention' mode + const requireMention = activation === "mention"; const mentionGate = resolveMentionGating({ requireMention, canDetectMention: true, wasMentioned, - implicitMention: isReplyToBot, - shouldBypassMention, + implicitMention: isReplyToBot, // treat reply-to-bot as an implicit mention + shouldBypassMention: safeShouldBypassMention, }); params.msg.wasMentioned = mentionGate.effectiveWasMentioned; if (!shouldProcess) { params.logVerbose( - `Group message stored for context (no mention detected) in ${params.conversationId}: ${params.msg.body}`, + `Group message stored for context (no activation pass) in ${params.conversationId}: ${params.msg.body}`, ); const sender = params.msg.senderName && params.msg.senderE164