Skip to content

fix(whatsapp): match reply bot ids without device suffix (#29023)#29112

Open
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/29023-whatsapp-reply-device-suffix
Open

fix(whatsapp): match reply bot ids without device suffix (#29023)#29112
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/29023-whatsapp-reply-device-suffix

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

What

WhatsApp group reply-to-bot detection fails when Baileys sends botIds with a multi-device numeric suffix (e.g. 15551230000@10@s.whatsapp.net) but quotedParticipant arrives without it (15551230000@s.whatsapp.net). The strict set-membership check rejects legitimate replies.

Root Cause

_bot_ids_from_message normalises :@ but stores only the full suffixed JID. quotedParticipant never carries the device segment, so "15551230000@s.whatsapp.net" in {"15551230000@10@s.whatsapp.net"} evaluates to False.

Fix

  • Add @staticmethod _without_whatsapp_device_suffix(value) that strips the device segment only when parts[1].isdigit() — a targeted guard that avoids stripping non-device segments like s in user@s.whatsapp.net.
  • Call it in _bot_ids_from_message to register both the original and suffix-stripped alias, so both the reply-check and mention-check code paths can match whichever format the incoming data supplies.

Testing

14 new regression tests (40 total in the file, all pass):

Test What it proves
TestWithoutDeviceSuffix (8 unit tests) Helper strips numeric device from s.whatsapp.net / lid, passes through no-suffix, non-numeric-middle, empty, bare-phone, two-segment JIDs
test_reply_to_bot_via_suffix_stripped_alias Reply detected at both _message_is_reply_to_bot and _should_process_message
test_reply_to_bot_via_raw_colon_format Works through the :@ normalisation path
test_reply_to_bot_legacy_no_suffix_still_works Non-multi-device botIds unaffected
test_reply_to_different_user_stays_blocked Negative case: reply to other user stays blocked
test_mention_also_matches_suffix_stripped_bot_ids Mention detection also matches via stripped alias
test_bot_ids_set_contains_both_suffixed_and_stripped Both original + alias present in the set

Fail-without-fix verified: reverting only gateway/platforms/whatsapp.py causes 2 tests to fail, 3 unaffected tests still pass.

Files Changed

  • gateway/platforms/whatsapp.py — +9 lines (extracted helper + one registration call)
  • tests/gateway/test_whatsapp_group_gating.py — +146 lines (14 new tests)

Fixes #29023

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/whatsapp WhatsApp Business adapter P2 Medium — degraded but workaround exists labels May 20, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #29049 — both PRs fix the same WhatsApp device suffix mismatch in _bot_ids_from_message (issue #29023). Also related to older PRs #11469 and #7323.

@Tranquil-Flow Tranquil-Flow force-pushed the fix/29023-whatsapp-reply-device-suffix branch from c276fe4 to cc1e0f0 Compare May 25, 2026 09:12
…h#29023)

Baileys' sock.user.{id,lid} include a multi-device numeric suffix
(e.g. 15551230000@10@s.whatsapp.net) but quotedParticipant arrives
without it (15551230000@s.whatsapp.net). Extract a static helper
_without_whatsapp_device_suffix that strips the device segment when the
middle part is purely numeric, and call it in _bot_ids_from_message to
produce a suffix-stripped alias alongside the original.

- Add @staticmethod _without_whatsapp_device_suffix with isdigit() guard
- Register both original and stripped IDs in _bot_ids_from_message
- Add 14 regression tests covering unit, integration, edge, and negative
  cases (40 total in test file, all pass)
- Fail-without-fix verified: 2 tests fail when production code is reverted

Fixes NousResearch#29023
@Tranquil-Flow Tranquil-Flow force-pushed the fix/29023-whatsapp-reply-device-suffix branch from cc1e0f0 to 645bd6c Compare May 25, 2026 11:03
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.

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

2 participants