fix(chatwoot): findContactByIdentifier runtime crash 'TypeError: client.get is not a function' & LID fallback issue
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
Hướng nghiên cứu
Bắt đầu với src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts và lần theo findContactByIdentifier cùng phương án dự phòng createConversation được mô tả trong issue. Kiểm tra cách Chatwoot client cung cấp chức năng tìm kiếm liên hệ và cách chọn JID từ xa khi thiếu remoteJidAlt. Cập nhật cả hai hành vi và chạy các bài kiểm thử liên quan đến việc tra cứu liên hệ Chatwoot và tạo cuộc hội thoại; hoàn tất khi việc xử lý lỗi 422 và thiếu JID thay thế không còn gây lỗi lúc chạy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- TypeScript
- Star
- 10.2k
- Fork
- 7.5k
- Merge trung bình
- 6 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của evolution-foundation/evolution-api
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
evolution-foundation/evolution-api#2796 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
evolution-foundation/evolution-api#2782 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
evolution-foundation/evolution-api#2723 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
evolution-foundation/evolution-api#2704 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
evolution-foundation/evolution-api#2702 · 3 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của evolution-foundation/evolution-api
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
abhigyanpatwari/GitNexus#4124 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
laaielichter/Godotwright#250 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
An Antigravity tab can quote an old Assist message as the owner's words in a resumed conversationĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Retry an empty final answer when Gemini reports MALFORMED_RESPONSE (gemini-4-hydrogen)Có thể đã có người làm @waleedkadous đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
iaser-ai/ansari#444 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Manager UI logo fails to load — broken external URLCó thể đã có người làm @kavindu-udara đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100