fix(chatwoot): handle missing remoteJidAlt for LID contacts without crashing - #2747
Open
abdulsametkarakayali wants to merge 1 commit into
Conversation
…rashing Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Reviewer's GuideUpdates Chatwoot conversation handling so unresolved WhatsApp LID contacts can be created using the LID as an identifier without persisting fake phone numbers, while making contact searches, mapping, and downstream JID parsing resilient to missing data and API failures. Sequence diagram for unresolved LID conversation creationsequenceDiagram
participant WA as WhatsApp
participant CW as ChatwootService
participant Search as Chatwoot contact search
participant C as Chatwoot conversation creation
WA->>CW: createConversation(remoteJid, remoteJidAlt?)
CW->>CW: resolveLidToPhone()
alt phone resolution succeeds
CW->>CW: findContact(phoneNumber)
else unresolved LID or missing remoteJidAlt
CW->>CW: phoneNumber = remoteJid
CW->>Search: findContactByIdentifier(remoteJid)
Search->>Search: contacts.search(q)
Search->>Search: POST contacts/filter
Search-->>CW: matching LID contact or null
end
CW->>C: create/update conversation using LID identifier
C-->>CW: conversation result
Flow diagram for safe LID contact mappingflowchart TD
A[Receive LID message] --> B{LID resolved to phone?}
B -->|Yes| C[Update phone contact mapping]
B -->|No| D[Fallback phoneNumber to remoteJid]
D --> E[Skip phone_number for @lid]
E --> F[Skip phone contact mapping]
F --> G[Search contact by identifier]
C --> H[Create or update conversation]
G --> H
H --> I[Optional JID parsing prevents missing-data crash]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the LID fallback or revised contact lookup is wrong, Chatwoot could create or update a contact with an incorrect identifier, and the resulting persisted contact or conversation data would remain after reverting. Those records are bounded and can be corrected or rebuilt, rather than causing an irreversible external side effect.
German-Caycedo-M
approved these changes
Oct 3, 2026
This branch has not been deployed
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
When a WhatsApp contact sends messages with
addressingMode: 'lid'butremoteJidAltis missing, ChatwootcreateConversationcan still drop the message.developalready hasresolveLidToPhone/saveLidMappingand safer splits. The remaining gap: ifresolveLidToPhonefails andremoteJidAltis absent,phoneNumberstaysundefinedand conversation creation returns null (Contact not created or found).findContactByIdentifieralso calledclient.get, which throwst.get is not a function.Fix
remoteJid(the LID itself) whenremoteJidAltis absent so conversation creation can proceed.phone_numberfor@lididentifiers (Sourcery).isLid && !remoteJidAlt) so we do not overwrite an unrelated phone contact (Sourcery).client.getinfindContactByIdentifierwithcontacts.search+contacts/filter..split()calls optional-chained and wrap LID mapping in try/catch.Notes
Replaces #2718, which targeted
main. This branch is based on currentdevelop.Related: #1872, #2324.
Summary by Sourcery
Handle unresolved WhatsApp LID contacts safely so messages can continue creating Chatwoot conversations without corrupting phone contact mappings.
Bug Fixes:
Enhancements: