fix(chatwoot): findContactByIdentifier runtime crash 'TypeError: client.get is not a function' & LID fallback issue
Maintainer antworten meist innerhalb von 4 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 76/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- typescript
Rechercherichtung
Beginne mit src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts und verfolge findContactByIdentifier sowie den im Issue beschriebenen Fallback von createConversation. Prüfe, wie der Chatwoot-Client die Kontaktsuche bereitstellt und wie die Remote-JID ausgewählt wird, wenn remoteJidAlt fehlt. Aktualisiere beide Verhaltensweisen und führe die relevanten Tests für die Chatwoot-Kontaktsuche und die Erstellung von Konversationen aus; fertig ist es, wenn die 422-Behandlung und die fehlende alternative JID keine Laufzeitfehler mehr verursachen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- TypeScript
- Sterne
- 10.2k
- Forks
- 7.5k
- Ø Merge
- 6 T. 19 Std.
- Gemergte PRs (30 T.)
- 4
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus evolution-foundation/evolution-api
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
evolution-foundation/evolution-api#2796 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
evolution-foundation/evolution-api#2782 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
evolution-foundation/evolution-api#2723 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
evolution-foundation/evolution-api#2704 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
evolution-foundation/evolution-api#2702 · 3 Kommentare · 3 Reaktionen ·
Maintainer antworten meist innerhalb von 4 Tagen
Alle Issues in evolution-foundation/evolution-api
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
abhigyanpatwari/GitNexus#4124 ·
Maintainer antworten meist innerhalb von 1 Tag
-
good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
laaielichter/Godotwright#250 ·
Maintainer antworten meist innerhalb von 1 Tag
-
An Antigravity tab can quote an old Assist message as the owner's words in a resumed conversationOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
-
Retry an empty final answer when Gemini reports MALFORMED_RESPONSE (gemini-4-hydrogen)Evtl. vergeben @waleedkadous hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
iaser-ai/ansari#444 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]: Manager UI logo fails to load — broken external URLEvtl. vergeben @kavindu-udara hat das heute übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100