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..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) { @@ -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 {