fix(whatsapp): match reply-to-bot when botIds carry device suffix#29049
Closed
luyao618 wants to merge 1 commit into
Closed
fix(whatsapp): match reply-to-bot when botIds carry device suffix#29049luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
Baileys delivers quotedParticipant without the multi-device suffix
(e.g. "5511999999999@s.whatsapp.net"), but sock.user.{id,lid} in
botIds carries one (e.g. "5511999999999@10@s.whatsapp.net"). The
strict set-membership check in _message_is_reply_to_bot therefore
always returned False on multi-device WhatsApp accounts, making the
reply-to-bot admission shortcut unusable for groups with
require_mention=true. This is especially bad for voice notes, which
cannot include text @mentions at all.
Expose a suffix-stripped alias alongside the original normalized id
so reply-to-bot detection succeeds for both multi-device and legacy
single-device accounts.
Fixes NousResearch#29023
Collaborator
This was referenced May 20, 2026
fix(gateway): recognize Windows drive-letter paths in extract_local_files() bare-path uploads
#28991
Closed
Contributor
Author
|
Closing — the failing |
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.
Summary
Fixes #29023. WhatsApp reply-to-bot detection (
_message_is_reply_to_bot) consistently returnedFalseon multi-device accounts because of a normalized-ID shape mismatch:quotedParticipantwithout the device suffix:"5511999999999@s.whatsapp.net"sock.user.{id,lid}populatesbotIdswith the device suffix (:N→ normalized to@N):"5511999999999@10@s.whatsapp.net"The set-membership check in
gateway/platforms/whatsapp.pytherefore never matched, breaking the reply-to-bot admission shortcut in groups configured withrequire_mention: true. This is especially painful for voice notes, where WhatsApp doesn't support text @mentions at all — there's literally no other way to wake the bot.Fix
In
_bot_ids_from_message, when a normalized bot id has three@-separated parts (i.e. carries a device suffix), add a suffix-stripped alias alongside the original. Legacy two-part ids are unchanged, so single-device accounts keep their existing behavior.This is exactly the patch the issue author proposed in the Fix section.
Tests
Added two regression tests in
tests/gateway/test_whatsapp_group_gating.py:test_reply_to_bot_matches_device_suffixed_bot_ids— multi-device botIds (:10suffix) + non-suffixedquotedParticipantmust match and admit the message underrequire_mention=true.test_reply_to_bot_legacy_non_multidevice_unchanged— legacy two-part ids continue to match as before.Risk
Tiny, surgical, single-function change. The added alias is only emitted when the id has a third
@-separated component, so it cannot affect legacy callers. No other code paths consume_bot_ids_from_messagein a way that would break on the extra alias (the other callers use it forsplit('@', 1)[0]bare-id extraction andin-checks againstmentionedIds).