Skip to content

fix(whatsapp): normalise bare phone numbers to JIDs before bridge send - #41667

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/whatsapp-bare-phone-jid-suffix
Closed

fix(whatsapp): normalise bare phone numbers to JIDs before bridge send#41667
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/whatsapp-bare-phone-jid-suffix

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Normalises bare phone numbers to full WhatsApp JIDs before posting to the Baileys bridge. Previously, send_message(target="whatsapp:15551234567") passed the raw number to the bridge, causing jidDecode() to return null and a 500 error.

Related Issue

Fixes #41660

Type of Change

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

Changes Made

  • gateway/platforms/whatsapp.py: Added _ensure_jid_suffix() static method that appends @s.whatsapp.net to any chat_id without an @ character. Called at entry point of send(), edit_message(), _send_media_to_bridge(), and send_typing().
  • tests/gateway/test_whatsapp_jid_suffix.py: 10 tests — 7 unit tests for the static method (bare number, already-JID, @lid, @g.us, empty, None, E.164 +prefix) + 3 integration tests verifying the bridge POST payload is normalised.

How to Test

pytest tests/gateway/test_whatsapp_jid_suffix.py -v
pytest tests/gateway/test_whatsapp_*.py -q   # all WhatsApp tests, no regression

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: macOS

Documentation & Housekeeping

  • I've updated relevant documentation — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've considered cross-platform impact — N/A (WhatsApp adapter only)

Code Intelligence

The Baileys bridge expects full WhatsApp JIDs (e.g.
`15551234567@s.whatsapp.net`).  When send_message() was called with a
bare phone number like `whatsapp:15551234567`, the Python adapter passed
the raw number to the bridge, causing `jidDecode()` to return null and
the bridge to crash with:

    Cannot destructure property 'user' of 'jidDecode(...)'

Add `_ensure_jid_suffix()` — a static method that appends
`@s.whatsapp.net` to any chat_id that doesn't already contain `@`.
Called at the entry point of `send()`, `edit_message()`,
`_send_media_to_bridge()`, and `send_typing()`.

Fixes NousResearch#41660
@teknium1

Copy link
Copy Markdown
Contributor

Fixed on main via #50379 (salvage of #8639) — bare WhatsApp phone targets are now normalized to <digits>@s.whatsapp.net before the bridge call at every outbound send site.

@sgaofen's #8639 was the earliest of this cluster, so it was used as the base and credited first; thanks @liuhao1024 for independently catching and fixing the same bug. Closing as duplicate.

@teknium1 teknium1 closed this Jun 21, 2026
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.

WhatsApp send fails with bare phone number — missing @s.whatsapp.net JID suffix

3 participants