Skip to content

fix(whatsapp): enforce require_mention in group chats - #4730

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-b9588524
Apr 3, 2026
Merged

fix(whatsapp): enforce require_mention in group chats#4730
teknium1 merged 2 commits into
mainfrom
hermes/hermes-b9588524

Conversation

@teknium1

@teknium1 teknium1 commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Brings WhatsApp group chat handling to parity with Telegram's mention gating system. Previously, every message in a WhatsApp group hit the agent. Now the bot only responds when directly triggered.

Cherry-picked from PR #4694 by @kshitijk4poor. Also supersedes #3636.

Changes

  • WhatsApp adapter (gateway/platforms/whatsapp.py): Add require_mention / mention_patterns / free_response_chats config support, mirroring Telegram's established pattern
  • Config bridging (gateway/config.py): Bridge whatsapp.require_mention, whatsapp.mention_patterns, and whatsapp.free_response_chats from config.yaml to env vars
  • WhatsApp bridge (scripts/whatsapp-bridge/bridge.js): Forward mentionedIds, quotedParticipant, botIds to adapter; refactor message body extraction to properly handle ephemeral/viewOnce/template messages
  • Tests (tests/gateway/test_whatsapp_group_gating.py): 10 test cases covering all gating scenarios

Config

whatsapp:
  require_mention: true
  mention_patterns:
    - "^\\s*hermes\\b"
  free_response_chats:
    - "120363001234567890@g.us"

Group message acceptance cascade

DMs always pass. Group messages are accepted when:

  1. Chat is in free_response_chats
  2. require_mention is disabled (default)
  3. Message is a /command
  4. Message replies to the bot
  5. Bot is @mentioned
  6. Body matches a mention_patterns regex

Backward compatible — defaults to require_mention: false.

Test results

  • 10/10 PR tests pass
  • 1831/1831 gateway tests pass (4 pre-existing failures unrelated to WhatsApp)
  • E2E verified: adapter gating, config bridging, ID normalization

…ctive message unwrapping

Address feature gaps vs Telegram/Discord/Mattermost adapters:
- free_response_chats whitelist to bypass mention gating per-group
- strip bot @phone mentions from body before forwarding to agent
- unwrap templateMessage/buttonsMessage/listMessage in bridge
- info-level log on successful mention pattern compilation
- use module-level json import instead of inline import in config
- eliminate double _normalize_whatsapp_id call via walrus operator
- hoist botIds computation outside per-message loop in bridge
@teknium1
teknium1 merged commit 7165eff into main Apr 3, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants