Skip to content

fix(whatsapp): normalize bare phone targets to JIDs (salvage #8639) - #50379

Merged
teknium1 merged 1 commit into
mainfrom
fix/whatsapp-jid-normalization-8639
Jun 21, 2026
Merged

fix(whatsapp): normalize bare phone targets to JIDs (salvage #8639)#50379
teknium1 merged 1 commit into
mainfrom
fix/whatsapp-jid-normalization-8639

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

WhatsApp sends to a bare phone number now reach the bridge as a valid JID instead of crashing it. Salvages #8639 (@sgaofen, earliest of the cluster) onto current main.

Baileys' jidDecode crashes — Cannot destructure property 'user' of jidDecode(...) as it is undefined — when handed a bare phone number, so send_message(target="whatsapp:+50766715226") and --deliver whatsapp:... cron jobs returned HTTP 500 and never delivered (#8637).

Changes

  • gateway/whatsapp_identity.py: add to_whatsapp_jid() — the outbound inverse of normalize_whatsapp_identifier. Bare phone (+50766715226 / 50766715226) → 50766715226@s.whatsapp.net; already-qualified JIDs (@g.us, @lid, status@broadcast, @newsletter) pass through unchanged. Single source of truth, beside the existing identity helpers — no duplicate normalizer.
  • plugins/platforms/whatsapp/adapter.py: apply it at all 6 outbound bridge call sites (send, edit, _send_media_to_bridge, send_typing, get_chat_info, and the standalone cron/send_message sender).
  • Tests: @sgaofen's adapter send-normalization test (adapted to the relocated plugin path) + a group-JID passthrough guard + a focused unit-test file for to_whatsapp_jid.

Salvage notes

The adapter was migrated to a bundled plugin and the identity helpers were extracted since #8639 was opened, so the original diff no longer applies. Reauthored onto current main:

  • Helper lives in whatsapp_identity.py (next to normalize_whatsapp_identifier) rather than a new private helper in the adapter.
  • Fixed a latent bug in the original :device@domain handling — replace(":", "@", 1) produced the broken 60123456789@47@s.whatsapp.net; now collapses correctly to 60123456789@s.whatsapp.net (matches how normalize_whatsapp_identifier splits on :).

Duplicate cluster closed with credit to @sgaofen (first): #15652, #25943, #40182, #41667, #41866, plus #14738 (lid-format variant).

Validation

Before After
send("+50766715226") payload chatId +50766715226 (bridge 500) 50766715226@s.whatsapp.net
group @g.us / @lid targets unchanged unchanged
cron _standalone_send path raw phone normalized JID

Targeted suite: 43 tests passed (tests/gateway/test_whatsapp_to_jid.py, tests/gateway/test_whatsapp_connect.py). E2E verified the real adapter.send() and _standalone_send() paths plus the strip→build round-trip invariant against a temp HERMES_HOME.

Closes #8637.

Infographic

whatsapp-jid-normalization

Baileys' jidDecode crashes ("Cannot destructure property 'user' of
jidDecode(...) as it is undefined") when handed a bare phone number, so
sending a WhatsApp message to +50766715226 / 50766715226 returned HTTP
500 and never delivered (#8637).

Add to_whatsapp_jid() to gateway/whatsapp_identity.py — the outbound
inverse of normalize_whatsapp_identifier: it builds the JID a send must
use (bare phone -> <digits>@s.whatsapp.net) and passes through already
qualified JIDs (@g.us, @lid, status@broadcast, @newsletter) unchanged.
Wire it at every outbound bridge call site in the WhatsApp adapter
(send, edit, media, typing, get_chat_info, and the standalone cron /
send_message sender).

Co-authored-by: Hermes Agent <noreply@nousresearch.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/whatsapp-jid-normalization-8639 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11337 on HEAD, 11336 on base (🆕 +1)

🆕 New issues (1):

Rule Count
unresolved-import 1
First entries
tests/gateway/test_whatsapp_to_jid.py:10: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`

✅ Fixed issues: none

Unchanged: 5951 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

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.

WhatsApp bridge crashes on bare phone numbers — missing JID normalization

3 participants