fix(whatsapp): match reply bot ids without device suffix (#29023)#29112
Open
Tranquil-Flow wants to merge 2 commits into
Open
fix(whatsapp): match reply bot ids without device suffix (#29023)#29112Tranquil-Flow wants to merge 2 commits into
Tranquil-Flow wants to merge 2 commits into
Conversation
Collaborator
c276fe4 to
cc1e0f0
Compare
…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
cc1e0f0 to
645bd6c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
WhatsApp group reply-to-bot detection fails when Baileys sends
botIdswith a multi-device numeric suffix (e.g.15551230000@10@s.whatsapp.net) butquotedParticipantarrives without it (15551230000@s.whatsapp.net). The strict set-membership check rejects legitimate replies.Root Cause
_bot_ids_from_messagenormalises:→@but stores only the full suffixed JID.quotedParticipantnever carries the device segment, so"15551230000@s.whatsapp.net" in {"15551230000@10@s.whatsapp.net"}evaluates toFalse.Fix
@staticmethod _without_whatsapp_device_suffix(value)that strips the device segment only whenparts[1].isdigit()— a targeted guard that avoids stripping non-device segments likesinuser@s.whatsapp.net._bot_ids_from_messageto 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):
TestWithoutDeviceSuffix(8 unit tests)test_reply_to_bot_via_suffix_stripped_alias_message_is_reply_to_botand_should_process_messagetest_reply_to_bot_via_raw_colon_format:→@normalisation pathtest_reply_to_bot_legacy_no_suffix_still_workstest_reply_to_different_user_stays_blockedtest_mention_also_matches_suffix_stripped_bot_idstest_bot_ids_set_contains_both_suffixed_and_strippedFail-without-fix verified: reverting only
gateway/platforms/whatsapp.pycauses 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