From 52140859ff30269162d99e890a7266a35cce567c Mon Sep 17 00:00:00 2001 From: Wahyu Saputra Date: Thu, 4 Dec 2025 10:52:40 +0700 Subject: [PATCH 1/2] fix(chatwoot): fallback when contact update fails --- CHANGELOG.md | 1 + .../chatbot/chatwoot/services/chatwoot.service.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d96c2103c..d793a0ad7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [WIDGET-WORKS] Guard `messages.update` cache cleanup with a derived key and optional `MESSAGE_UPDATE_CACHE_DELETE_DISABLED` flag to prevent cache.delete crash-loops. * [WIDGET-WORKS] Save messages before Chatwoot sync in `/message/sendText` to avoid missing `chatwootMessageId` and log async sync failures. * [WIDGET-WORKS] Skip Chatwoot sync in `messages.upsert` when a message key already has `chatwootMessageId` (handles Chatwoot automation echoes/duplicates). +* [WIDGET-WORKS] Avoid dropping group conversations when Chatwoot `updateContact` fails by logging the error and continuing with the existing contact. ### Features diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index badaba136..95949fd2d 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -370,6 +370,7 @@ export class ChatwootService { return contact; } catch (error) { + this.logger.error(`[WIDGET-WORKS] updateContact failed: ${error?.message || error}`); return null; } } @@ -712,11 +713,18 @@ export class ChatwootService { this.logger.verbose(`Picture needs update: ${pictureNeedsUpdate}`); this.logger.verbose(`Name needs update: ${nameNeedsUpdate}`); if (pictureNeedsUpdate || nameNeedsUpdate) { - contact = await this.updateContact(instance, contact.id, { + const updatedContact = await this.updateContact(instance, contact.id, { ...(nameNeedsUpdate && { name: nameContact }), ...(waProfilePictureFile === '' && { avatar: null }), ...(pictureNeedsUpdate && { avatar_url: picture_url?.profilePictureUrl }), }); + + // [WIDGET-WORKS] Avoid nulling the contact when updateContact fails; keep existing contact to continue sync. + if (updatedContact) { + contact = updatedContact; + } else { + this.logger.warn('[WIDGET-WORKS] Failed to update contact; continuing with existing contact'); + } } } } else { From e72ca33fe8e023537f8bdc580da0d02b7e416fc3 Mon Sep 17 00:00:00 2001 From: Wahyu Saputra Date: Thu, 4 Dec 2025 10:59:43 +0700 Subject: [PATCH 2/2] chore(chatwoot): type updateContact return --- .../integrations/chatbot/chatwoot/services/chatwoot.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index 95949fd2d..cb2232ac4 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -348,7 +348,7 @@ export class ChatwootService { } } - public async updateContact(instance: InstanceDto, id: number, data: any) { + public async updateContact(instance: InstanceDto, id: number, data: any): Promise { const client = await this.clientCw(instance); if (!client) {