Skip to content

fix(whatsapp): strip device suffix in ID normalization#7323

Open
cosmic-hiker wants to merge 1 commit into
NousResearch:mainfrom
cosmic-hiker:fix/whatsapp-id-normalization
Open

fix(whatsapp): strip device suffix in ID normalization#7323
cosmic-hiker wants to merge 1 commit into
NousResearch:mainfrom
cosmic-hiker:fix/whatsapp-id-normalization

Conversation

@cosmic-hiker

Copy link
Copy Markdown

What does this PR do?

Fixes WhatsApp ID normalization for multi-device JIDs. The format is number:device@domain (e.g. 4912345678:3@s.whatsapp.net). The previous logic used str.replace(":", "@", 1) which produced number@device@domain — a malformed ID with two @ signs.

This broke bot-self detection, mention matching, and quoted-participant checks whenever the bot or a mentioned user had a device suffix in their JID.

Fix: find the colon and @ positions, then slice out the :device segment to produce number@domain. Applied to both the Python adapter and the Node.js bridge so they stay in sync.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/platforms/whatsapp.py_normalize_whatsapp_id(): replace naive str.replace(":", "@", 1) with position-based slicing that correctly strips the device suffix
  • scripts/whatsapp-bridge/bridge.jsnormalizeWhatsAppId(): same fix on the JS side so bridge and adapter stay in sync
  • tests/gateway/test_whatsapp_id_normalization.py — new parametrized test covering device suffixes, LID format, group IDs, clean IDs, and edge cases (12 cases)

How to Test

  1. Run the new tests: pytest tests/gateway/test_whatsapp_id_normalization.py -v
  2. Connect a WhatsApp account with multi-device enabled
  3. Send a message to a group where the bot is present — verify the bot detects its own messages and does not reply to itself
  4. Reply to a bot message in a group — verify quoted-participant matching works

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: Pop!_OS (Ubuntu-based) Linux

Documentation & Housekeeping

  • I've updated relevant documentation — N/A (bug fix, no new config)
  • I've considered cross-platform impact — N/A (string operations only)

WhatsApp multi-device IDs use the format "number:device@domain" (e.g.
"4912345678:3@s.whatsapp.net"). The previous normalization logic used
str.replace(":", "@", 1) which produced "number@device@domain" — a
malformed ID with two @ signs.

This broke bot-self detection, mention matching, and quoted-participant
checks whenever the bot or a mentioned user had a device suffix in their
JID.

Fix: find the colon and @ positions, then slice out the ":device" segment
to produce "number@domain". Applied to both the Python adapter and the
Node.js bridge so they stay in sync.

Includes parametrized tests covering device suffixes, LID format, group
IDs, clean IDs, and edge cases.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/whatsapp WhatsApp Business adapter labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #11469 — both fix WhatsApp JID device suffix handling for group reply detection. Different approaches to the same root cause (Baileys multi-device JID format).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery 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