Skip to content

Let fromMe messages through in groups under self-chat mode - #15326

Closed
jscholz wants to merge 1 commit into
NousResearch:mainfrom
jscholz:fix-whatsapp-bridge-group-fromme
Closed

Let fromMe messages through in groups under self-chat mode#15326
jscholz wants to merge 1 commit into
NousResearch:mainfrom
jscholz:fix-whatsapp-bridge-group-fromme

Conversation

@jscholz

@jscholz jscholz commented Apr 24, 2026

Copy link
Copy Markdown

Summary

In scripts/whatsapp-bridge/bridge.js, the fromMe branch of the messages.upsert handler bails out on any group chat:

if (msg.key.fromMe) {
  if (isGroup || chatId.includes('status')) continue;
  ...
}

That drops every message the paired user sends in any group, which breaks a legitimate self-chat-mode flow: a user with a single paired WhatsApp number wants to @mention their own bot from a group they're in alongside other humans (e.g. "@Mybot check my calendar"). Under the current code the bridge never sees those messages.

Use case

  • Self-chat mode (WHATSAPP_MODE !== 'bot'): the agent is paired to the user's own number.
  • The user is in a group with friends / family / coworkers.
  • They want to trigger the agent from that group via @mention, just like any other group member would trigger a normal bot.

With this patch applied they can.

Why the guard was redundant

The echo-loop concern that seemed to motivate dropping all group fromMe messages is already handled ~60 lines below:

if (msg.key.fromMe && ((REPLY_PREFIX && body.startsWith(REPLY_PREFIX)) || recentlySentIds.has(msg.key.id))) {
  ...
}

That check — REPLY_PREFIX + recentlySentIds — is the real loop-breaker: it catches any message the bridge itself just sent, regardless of whether the chat is a group or a DM. The earlier blanket isGroup drop was a second, overly broad line of defense that also blocked legitimate user input.

What changes

  • Still skip status@broadcast-style chats unconditionally (always correct to drop).
  • Bot mode (WHATSAPP_MODE === 'bot') still unconditionally skips every fromMe — in that deployment the bridge runs on a separate number, so every fromMe really is a bridge echo.
  • Self-chat mode: no longer bails on isGroup. Groups are now a valid context for the paired user to address the bot.
  • Self-chat mode 1:1 chats still require the chat to be the user's own self-chat (same LID/phone match as before), so the bot doesn't try to respond on the user's behalf in DMs with arbitrary contacts.

Diff shape

Before:

if (msg.key.fromMe) {
  if (isGroup || chatId.includes('status')) continue;
  if (WHATSAPP_MODE === 'bot') continue;
  // self-chat check
  const isSelfChat = ...;
  if (!isSelfChat) continue;
}

After:

if (msg.key.fromMe) {
  if (chatId.includes('status')) continue;
  if (WHATSAPP_MODE === 'bot') continue;
  if (!isGroup) {
    const isSelfChat = ...;
    if (!isSelfChat) continue;
  }
}

Test plan

  • Self-chat mode, 1:1 with a random contact (not the self-chat): still ignored (no isSelfChat).
  • Self-chat mode, user's own self-chat: processed (unchanged).
  • Self-chat mode, group containing the user: user's own messages now reach the allowlist + handler path; bridge's own outgoing replies are still filtered by the downstream REPLY_PREFIX / recentlySentIds guard (no echo loop).
  • Bot mode, any chat: all fromMe still dropped (unchanged).
  • status@broadcast messages: still dropped (unchanged).

🤖 Generated with Claude Code

… mode

The early-exit `if (isGroup || chatId.includes('status')) continue;` in
the fromMe branch of the messages.upsert handler was too aggressive: it
silently dropped every message you sent in any group, which makes it
impossible to @mention your own bot from a group you're in. That's a
common self-chat-mode use case (one paired number, bot addressed via
@mention alongside other humans).

This change:

- Keeps the status-broadcast skip (always correct to drop).
- Keeps bot mode's unconditional fromMe skip (separate number -> every
  fromMe is a bridge echo; dropping is right).
- In self-chat mode, stops bailing on `isGroup`. Groups are now a valid
  context for the user to address the bot from their paired account.
- For 1:1 chats, preserves the existing self-chat check so the bot
  doesn't respond on the user's behalf in arbitrary DMs.

The echo-loop concern this guard seemed aimed at is already handled
downstream (~line 327) by the REPLY_PREFIX + recentlySentIds check,
which catches any message the bridge itself just sent. That's the real
loop-breaker; the group drop here was redundant and blocked a
legitimate flow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists platform/whatsapp WhatsApp Business adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants