fix(whatsapp): safe handling for new activation modes (reply/never) and explicit mention gating
This commit is contained in:
parent
dd5fd12f52
commit
9f96b61468
@ -114,30 +114,34 @@ export function applyGroupGating(params: {
|
|||||||
(selfE164 && replySenderE164 && selfE164 === replySenderE164),
|
(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
|
// Determine if we should process based on activation mode
|
||||||
const shouldProcess = (() => {
|
const shouldProcess = (() => {
|
||||||
if (activation === "always") return true;
|
if (activation === "always") return true;
|
||||||
if (activation === "never") return shouldBypassMention;
|
if (activation === "never") return safeShouldBypassMention;
|
||||||
if (activation === "replies") return isReplyToBot || shouldBypassMention;
|
if (activation === "replies") return isReplyToBot || safeShouldBypassMention;
|
||||||
if (activation === "mention+replies")
|
if (activation === "mention+replies")
|
||||||
return wasMentioned || isReplyToBot || shouldBypassMention;
|
return wasMentioned || isReplyToBot || safeShouldBypassMention;
|
||||||
// Default to "mention" mode
|
// 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({
|
const mentionGate = resolveMentionGating({
|
||||||
requireMention,
|
requireMention,
|
||||||
canDetectMention: true,
|
canDetectMention: true,
|
||||||
wasMentioned,
|
wasMentioned,
|
||||||
implicitMention: isReplyToBot,
|
implicitMention: isReplyToBot, // treat reply-to-bot as an implicit mention
|
||||||
shouldBypassMention,
|
shouldBypassMention: safeShouldBypassMention,
|
||||||
});
|
});
|
||||||
params.msg.wasMentioned = mentionGate.effectiveWasMentioned;
|
params.msg.wasMentioned = mentionGate.effectiveWasMentioned;
|
||||||
|
|
||||||
if (!shouldProcess) {
|
if (!shouldProcess) {
|
||||||
params.logVerbose(
|
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 =
|
const sender =
|
||||||
params.msg.senderName && params.msg.senderE164
|
params.msg.senderName && params.msg.senderE164
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user