Skip to content

[Bug]: WhatsApp reply-to-bot detection fails — device suffix mismatch in botIds vs quotedParticipant #29023

@kruzerbot

Description

@kruzerbot

[Bug]: WhatsApp reply-to-bot detection fails — device suffix mismatch breaks _message_is_reply_to_bot

Summary

The _message_is_reply_to_bot() method in gateway/platforms/whatsapp.py consistently returns False for WhatsApp group messages, even when the user explicitly replies (quotes) a bot message. This makes the reply-to-bot admission shortcut unusable on WhatsApp.

Impact: Users in groups with require_mention: true cannot trigger the bot by replying to its messages — they must always @mention the bot, which is impossible for voice/audio messages since WhatsApp voice notes cannot include text mentions.

Root Cause

The bridge sends botIds with the device suffix included (:N → normalized to @N):

// bridge.js line ~244-247
const botIds = Array.from(new Set([
    normalizeWhatsAppId(sock.user?.id),     // "5511999999999@10@s.whatsapp.net"
    normalizeWhatsAppId(sock.user?.lid),    // "99999999999999@10@lid"
].filter(Boolean)));

However, the quotedParticipant from Baileys contextInfo (extracted at bridge.js line ~321) arrives without the device suffix:

quotedParticipant: "5511999999999@s.whatsapp.net"    // no @10
botIds:          {"5511999999999@10@s.whatsapp.net", "99999999999999@10@lid"}

Since _message_is_reply_to_bot() does a strict set membership check:

def _message_is_reply_to_bot(self, data: Dict[str, Any]) -> bool:
    quoted_participant = self._normalize_whatsapp_id(data.get("quotedParticipant"))
    if not quoted_participant:
        return False
    return quoted_participant in self._bot_ids_from_message(data)

The match always fails: "5511999999999@s.whatsapp.net" in {"5511999999999@10@s.whatsapp.net", "99999999999999@10@lid"}False.

Environment

  • Platform: WhatsApp (Baileys bridge, multi-device)
  • Hermes version: Observed May 2026
  • Affected: All WhatsApp groups with require_mention: true

Reproduction

  1. Configure whatsapp.require_mention: true in config.yaml
  2. Join a WhatsApp group with the bot
  3. Have the bot send any message in the group
  4. Reply (quote) the bots message with a text reply
  5. Expected: Bot processes the reply without needing @mention
  6. Actual: Bot silently ignores the message — _message_is_reply_to_bot returns False

Fix

In gateway/platforms/whatsapp.py, modify _bot_ids_from_message() to also generate ID variants without the device suffix:

def _bot_ids_from_message(self, data: Dict[str, Any]) -> set[str]:
    bot_ids = set()
    for candidate in data.get("botIds") or []:
        normalized = self._normalize_whatsapp_id(candidate)
        if normalized:
            bot_ids.add(normalized)
            # Also add without the device suffix (e.g., "5511999999999@10@s.whatsapp.net" -> "5511999999999@s.whatsapp.net")
            parts = normalized.split("@")
            if len(parts) > 2:
                bot_ids.add(f"{parts[0]}@{parts[-1]}")
    return bot_ids

This is safe for both multi-device and non-multi-device:

  • Multi-device: 5511999999999@10@s.whatsapp.net → adds alias 5511999999999@s.whatsapp.net
  • Legacy: 5511999999999@s.whatsapp.netlen(parts) is 2 → no alias added, original behavior preserved

Workaround

  • Disable require_mention globally (not recommended for noisy groups)
  • Use free_response_chats with the specific group JID (allows all messages, not just replies)
  • Users must @mention the bot (impossible for voice messages)

Type of Change

  • 🐛 Bug fix

Files Changed

  • gateway/platforms/whatsapp.py_bot_ids_from_message() — 3 lines added

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliveryplatform/whatsappWhatsApp Business adaptertype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions