fix(chatwoot): findContactByIdentifier runtime crash 'TypeError: client.get is not a function' & LID fallback issue
Les mainteneurs répondent en général sous 4 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 76/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- typescript
Piste de recherche
Commencez par src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts et suivez findContactByIdentifier ainsi que le fallback de createConversation décrit dans l’issue. Vérifiez comment le client Chatwoot expose la recherche de contacts et comment le JID distant est sélectionné lorsque remoteJidAlt est absent. Mettez à jour ces deux comportements et exécutez les tests pertinents pour la recherche de contacts Chatwoot et la création de conversations ; le travail est terminé lorsque la récupération après l’erreur 422 et l’absence du JID alternatif ne provoquent plus d’erreurs à l’exécution.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
When using the native Chatwoot integration with Evolution API, a critical runtime error occurs that causes incoming WhatsApp messages to fail and get dropped silently in ChatwootService:
TypeError: t.get is not a function in findContactByIdentifier:
When an incoming message arrives and Chatwoot returns 422 Unprocessable Entity on contact creation (e.g., when the identifier or phone number is already associated with an existing contact in Chatwoot), Evolution API attempts to recover by calling findContactByIdentifier(instance, identifier).
Inside findContactByIdentifier, it calls:
const contact = (await (client as any).get('contacts/search', { params: { q: identifier, sort: 'name' } }));
However, at runtime, the ChatwootClient instance returned by clientCw does not expose a root .get() method. It crashes with:
ERROR [ChatwootService] Error in createConversation: TypeError: t.get is not a function
WARN [ChatwootService] conversation not found
Additionally, in createConversation:
const i = s && !a ? t.key.remoteJidAlt : t.key.remoteJid;
When a user sends a message from a Linked Device / WhatsApp privacy mode where remoteJidAlt is undefined in that packet, i becomes undefined, causing downstream calls like i.split('@')[0] to throw TypeError: Cannot read properties of undefined (reading 'split').
Steps to Reproduce
- Connect WhatsApp with Chatwoot native integration enabled (
/chatwoot/set/:instance). - In Chatwoot, have an existing contact where
identifiermatches the incoming sender's WhatsApp JID but the stored phone number differs or has conflict. - Send a message to the instance from that WhatsApp number.
- Chatwoot returns
422on contact creation because the identifier is already registered. - Evolution API enters the 422 catch block and executes
this.findContactByIdentifier(...). - Watch Evolution API logs throw
TypeError: t.get is not a functionand fail to create the conversation.
Source Code References
File: src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts
-
findContactByIdentifierruntime failure:async findContactByIdentifier(instance: InstanceDto, identifier: string) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } // BUG: client is a ChatwootClient instance, not an Axios instance. Calling .get() fails at runtime. const contact = (await (client as any).get('contacts/search', { params: { q: identifier, sort: 'name' }, })) as any; -
LID
remoteJidAltundefined issue:// BUG: if remoteJidAlt is undefined, i becomes undefined const i = s && !a ? t.key.remoteJidAlt : t.key.remoteJid;
Suggested Fix
-
In
findContactByIdentifier, query contacts viaclient.contacts.search:async findContactByIdentifier(instance: InstanceDto, identifier: string) { const client = await this.clientCw(instance); if (!client) { this.logger.warn('client not found'); return null; } try { const res = await client.contacts.search({ accountId: this.provider.accountId, q: identifier, }); if (res?.payload?.length > 0) { return res.payload[0]; } } catch (err) { this.logger.error(`Error searching contact by identifier: ${err}`); } return null; } -
In
createConversation, fallback tot.key.remoteJidifremoteJidAltis missing:const i = s && !a ? (t.key.remoteJidAlt || t.key.remoteJid) : t.key.remoteJid;
Environment
- Evolution API Version: v2.3.7
- Chatwoot Version: v3.x / v4.x
- Deployment: Docker / Linux
- Langage dominant
- TypeScript
- Étoiles
- 10.2k
- Forks
- 7.5k
- Merge moyen
- 6 j 19 h
- PR mergées (30 j)
- 4
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de evolution-foundation/evolution-api
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
evolution-foundation/evolution-api#2796 ·
Les mainteneurs répondent en général sous 4 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
evolution-foundation/evolution-api#2782 ·
Les mainteneurs répondent en général sous 4 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
evolution-foundation/evolution-api#2723 ·
Les mainteneurs répondent en général sous 4 jours
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
evolution-foundation/evolution-api#2704 ·
Les mainteneurs répondent en général sous 4 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
evolution-foundation/evolution-api#2702 · 3 commentaires · 3 réactions ·
Les mainteneurs répondent en général sous 4 jours
Toutes les issues de evolution-foundation/evolution-api
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
abhigyanpatwari/GitNexus#4124 ·
Les mainteneurs répondent en général sous 1 jour
-
good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
laaielichter/Godotwright#250 ·
Les mainteneurs répondent en général sous 1 jour
-
An Antigravity tab can quote an old Assist message as the owner's words in a resumed conversationOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
Retry an empty final answer when Gemini reports MALFORMED_RESPONSE (gemini-4-hydrogen)Peut-être pris @waleedkadous l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
iaser-ai/ansari#444 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
[Bug]: Manager UI logo fails to load — broken external URLPeut-être pris @kavindu-udara l’a pris aujourd’hui. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100