fix(whatsapp): resolve LID addressing on Evolution inbound (use remoteJidAlt)#112
Open
firstplaceservdig1 wants to merge 2 commits into
Open
Conversation
…eJidAlt) WhatsApp's LID addressing mode (2024+ privacy) delivers 1:1 messages with remoteJid "<id>@lid" instead of the phone JID. jid_type then returned 'lid', message_processable? rejected it, and the message was silently dropped. In one production deployment this was ~99.6% of inbound 1:1 traffic. Evolution ships the real phone JID in remoteJidAlt. Add effective_remote_jid to prefer remoteJidAlt whenever the primary JID is a @lid, and use it from jid_type and phone_number_from_jid. Falls back to the raw lid when remoteJidAlt is absent. Adds spec covering LID resolution, the no-remoteJidAlt fallback, and a normal 1:1 regression guard. Refs evolution-foundation/evo-crm-community#49
Reviewer's guide (collapsed on small PRs)Reviewer's GuideImplements LID-aware JID resolution for WhatsApp Evolution inbound messages by introducing an effective_remote_jid helper, wiring it into JID classification and phone extraction, and adding targeted specs to ensure 1:1 LID messages are processed instead of dropped. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Now that
effective_remote_jidencapsulates the LID resolution logic, consider using it anywhere else that readsremoteJid(e.g., other helpers that infer behavior from the JID) to avoid future divergence in how inbound messages are interpreted. - If there’s a chance that
remoteJidAltcould also be a LID-style value in some future Evolution/WhatsApp change, you may want to defensively handle that (e.g., by only preferringremoteJidAltwhen it looks like a standard user JID) to avoid misclassification.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Now that `effective_remote_jid` encapsulates the LID resolution logic, consider using it anywhere else that reads `remoteJid` (e.g., other helpers that infer behavior from the JID) to avoid future divergence in how inbound messages are interpreted.
- If there’s a chance that `remoteJidAlt` could also be a LID-style value in some future Evolution/WhatsApp change, you may want to defensively handle that (e.g., by only preferring `remoteJidAlt` when it looks like a standard user JID) to avoid misclassification.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- effective_remote_jid: only prefer remoteJidAlt when it is a real (non-LID) JID, guarding against a future payload where the alternate is also LID-style. - group_jid: route through effective_remote_jid so the remote JID is interpreted in one place (no behavior change today; group JIDs are @g.us). - spec: add a case where remoteJidAlt is itself a @lid (stays 'lid', dropped). Addresses Sourcery review feedback on evolution-foundation#112.
Author
|
Thanks @sourcery-ai — both addressed in the latest commit:
|
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.
Problem
WhatsApp's LID addressing mode (2024+ privacy feature) delivers 1:1 messages with
remoteJid: "<id>@lid"instead of the phone JID. On the Evolution path:jid_type(evolution_handlers/helpers.rb) returns'lid'for@lidmessage_processable?only acceptsjid_type in %w[user group]→ the message is silently dropped (no contact, no conversation, no log beyond the event). In one production deployment this was ~99.6% of inbound 1:1 traffic (1096
@lidvs 4@s.whatsapp.netover 30 days). Related to #19 (which covers the outgoing side).Fix
Evolution already ships the real phone JID in
remoteJidAlt. Addeffective_remote_jidthat prefersremoteJidAltwhenever the primary JID is a@lid, and use it fromjid_typeandphone_number_from_jid. Falls back to the raw@lidwhenremoteJidAltis absent (no behavior change in that case).Verified in production
After deploying, 1:1 messages in LID mode now create a contact with the real phone number (from
remoteJidAlt) plus a conversation — instead of being dropped.Tests
Adds
spec/services/whatsapp/incoming_message_evolution_service_lid_spec.rb:remoteJidAlt→jid_type == 'user', phone extracted fromremoteJidAlt,message_processable?trueremoteJidAlt→ graceful fallback tolid@s.whatsapp.net→ unchanged (regression guard)Refs
#19 (LID addressing — outgoing). This addresses the inbound 1:1 side.
Summary by Sourcery
Handle WhatsApp Evolution inbound messages that use LID addressing by resolving the effective remote JID from remoteJidAlt so 1:1 messages are processed instead of dropped.
Bug Fixes:
Tests: