fix(chatwoot): findContactByIdentifier runtime crash 'TypeError: client.get is not a function' & LID fallback issue
維護者通常 4 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 76/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
研究方向
從src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts開始,追蹤findContactByIdentifier以及 issue 中描述的createConversation備援邏輯。檢查 Chatwoot 用戶端如何提供聯絡人搜尋功能,以及缺少remoteJidAlt時如何選擇遠端 JID。更新這兩種行為,並執行與 Chatwoot 聯絡人查找和對話建立相關的測試;當 422 錯誤復原處理和缺少替代 JID 不再造成執行階段錯誤時,即為完成。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- TypeScript
- 星號
- 10.2k
- 分支
- 7.5k
- 平均合併
- 6 天 19 小時
- 30 天內合併 PR
- 4
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
evolution-foundation/evolution-api 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
evolution-foundation/evolution-api#2796 ·
維護者通常 4 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
evolution-foundation/evolution-api#2782 ·
維護者通常 4 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
evolution-foundation/evolution-api#2723 ·
維護者通常 4 天內回覆
-
難度 1/5 1-3 小時 新手友好度 88/100
evolution-foundation/evolution-api#2704 ·
維護者通常 4 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 68/100
evolution-foundation/evolution-api#2702 · 3 則留言 · 3 個 reaction ·
維護者通常 4 天內回覆
查看 evolution-foundation/evolution-api 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
abhigyanpatwari/GitNexus#4124 ·
維護者通常 1 天內回覆
-
good first issue
難度 2/5 1-3 小時 新手友好度 72/100
laaielichter/Godotwright#250 ·
維護者通常 1 天內回覆
-
An Antigravity tab can quote an old Assist message as the owner's words in a resumed conversation未關閉
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
Retry an empty final answer when Gemini reports MALFORMED_RESPONSE (gemini-4-hydrogen)可能已有人在做 @waleedkadous 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
[Bug]: Manager UI logo fails to load — broken external URL可能已有人在做 @kavindu-udara 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 68/100