mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
whatsapp-bridge: allow fromMe+isGroup messages through
The fromMe handler in self-chat mode unconditionally bailed on group
messages with `if (isGroup || chatId.includes('status')) continue`,
meaning the user could never @mention their own bot in a group they
were in. This is an over-aggressive echo-loop guard — the real
loop-prevention already exists ~60 lines below at the REPLY_PREFIX +
recentlySentIds check, which catches messages the bridge itself sent.
Split the condition: still skip status broadcasts, but let group
messages continue. For 1:1 fromMe messages, preserve the existing
self-chat requirement (so the bot doesn't try to answer on the
user's behalf in random conversations).
Companion to the sender-identity prefix patch in gateway/platforms/
whatsapp.py — without this fix, the user themselves cannot
participate in a group conversation with their bot, so the sender
prefixing alone is only half the fix needed to make group chat
safely usable.
This commit is contained in:
parent
af4e1c833e
commit
5e68b7dc83
1 changed files with 19 additions and 10 deletions
|
|
@ -209,22 +209,31 @@ async function startSocket() {
|
|||
|
||||
// Handle fromMe messages based on mode
|
||||
if (msg.key.fromMe) {
|
||||
if (isGroup || chatId.includes('status')) continue;
|
||||
if (chatId.includes('status')) continue; // never process status broadcasts
|
||||
|
||||
if (WHATSAPP_MODE === 'bot') {
|
||||
// Bot mode: separate number. ALL fromMe are echo-backs of our own replies — skip.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Self-chat mode: only allow messages in the user's own self-chat
|
||||
// WhatsApp now uses LID (Linked Identity Device) format: 67427329167522@lid
|
||||
// AND classic format: 34652029134@s.whatsapp.net
|
||||
// sock.user has both: { id: "number:10@s.whatsapp.net", lid: "lid_number:10@lid" }
|
||||
const myNumber = (sock.user?.id || '').replace(/:.*@/, '@').replace(/@.*/, '');
|
||||
const myLid = (sock.user?.lid || '').replace(/:.*@/, '@').replace(/@.*/, '');
|
||||
const chatNumber = chatId.replace(/@.*/, '');
|
||||
const isSelfChat = (myNumber && chatNumber === myNumber) || (myLid && chatNumber === myLid);
|
||||
if (!isSelfChat) continue;
|
||||
// Self-chat mode. Groups and your own self-chat are both
|
||||
// valid contexts for YOU to address the bot from your own
|
||||
// paired account. The real echo-loop guard is at the
|
||||
// REPLY_PREFIX + recentlySentIds check ~60 lines below —
|
||||
// that catches messages the bridge itself sent. Bailing on
|
||||
// `isGroup` here would mean you can never @mention the bot
|
||||
// in a group you're in.
|
||||
//
|
||||
// For 1:1 chats: still require it be your self-chat (not a
|
||||
// DM to some other contact) so the bot doesn't try to
|
||||
// answer on your behalf in random conversations.
|
||||
if (!isGroup) {
|
||||
const myNumber = (sock.user?.id || '').replace(/:.*@/, '@').replace(/@.*/, '');
|
||||
const myLid = (sock.user?.lid || '').replace(/:.*@/, '@').replace(/@.*/, '');
|
||||
const chatNumber = chatId.replace(/@.*/, '');
|
||||
const isSelfChat = (myNumber && chatNumber === myNumber) || (myLid && chatNumber === myLid);
|
||||
if (!isSelfChat) continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Check allowlist for messages from others (resolve LID ↔ phone aliases)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue