fix(chatwoot): findContactByIdentifier runtime crash 'TypeError: client.get is not a function' & LID fallback issue
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
Research direction
Start with src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts and trace findContactByIdentifier plus the createConversation fallback described in the issue. Check how the Chatwoot client exposes contact search and how the remote JID is selected when remoteJidAlt is missing. Update both behaviors and run the relevant tests for Chatwoot contact lookup and conversation creation; done when the 422 recovery and missing alternate JID no longer cause runtime errors.
Written by the indexing model from the issue text.
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
- Dominant language
- TypeScript
- Stars
- 10.2k
- Forks
- 7.5k
- Avg merge
- 6d 19h
- Merged PRs (30d)
- 4
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from evolution-foundation/evolution-api
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
evolution-foundation/evolution-api#2796 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
evolution-foundation/evolution-api#2782 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
evolution-foundation/evolution-api#2723 ·
Maintainers usually reply within 4 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
evolution-foundation/evolution-api#2704 ·
Maintainers usually reply within 4 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
evolution-foundation/evolution-api#2702 · 3 comments · 3 reactions ·
Maintainers usually reply within 4 days
All issues in evolution-foundation/evolution-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
abhigyanpatwari/GitNexus#4124 ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
laaielichter/Godotwright#250 ·
Maintainers usually reply within 1 day
-
An Antigravity tab can quote an old Assist message as the owner's words in a resumed conversationOpen
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Retry an empty final answer when Gemini reports MALFORMED_RESPONSE (gemini-4-hydrogen)Possibly taken @waleedkadous claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
iaser-ai/ansari#444 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug]: Manager UI logo fails to load — broken external URLPossibly taken @kavindu-udara claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100