From 96043a8f7e484d6b598ffb074dde24fce331059b Mon Sep 17 00:00:00 2001 From: Daniel Sateler Date: Thu, 26 Feb 2026 12:43:24 -0300 Subject: [PATCH] fix(whatsapp): skip agent's own replies in bridge message handler --- scripts/whatsapp-bridge/bridge.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/whatsapp-bridge/bridge.js b/scripts/whatsapp-bridge/bridge.js index 796b30ff9a..48e4d880b0 100644 --- a/scripts/whatsapp-bridge/bridge.js +++ b/scripts/whatsapp-bridge/bridge.js @@ -111,10 +111,15 @@ async function startSocket() { const senderNumber = senderId.replace(/@.*/, ''); // Skip own messages UNLESS it's a self-chat ("Message Yourself") - // Self-chat JID ends with the user's own number - if (msg.key.fromMe && !chatId.includes('status') && isGroup) continue; - // In non-group chats, fromMe means we sent it — skip unless allowed user sent to themselves - if (msg.key.fromMe && !isGroup && ALLOWED_USERS.length > 0 && !ALLOWED_USERS.includes(senderNumber)) continue; + if (msg.key.fromMe) { + // Always skip in groups and status + if (isGroup || chatId.includes('status')) continue; + // In DMs: only allow self-chat (remoteJid matches our own number) + const myNumber = (sock.user?.id || '').replace(/:.*@/, '@').replace(/@.*/, ''); + const chatNumber = chatId.replace(/@.*/, ''); + const isSelfChat = myNumber && chatNumber === myNumber; + if (!isSelfChat) continue; + } // Check allowlist for messages from others if (!msg.key.fromMe && ALLOWED_USERS.length > 0 && !ALLOWED_USERS.includes(senderNumber)) {