From 59be4a780f8def2b050cc6df4076819ee4f36e81 Mon Sep 17 00:00:00 2001 From: devlikepro Date: Fri, 26 Sep 2025 09:48:20 +0700 Subject: [PATCH] [core] ChatWoot - check attributes before updating fix #1173 --- src/apps/chatwoot/client/ContactAPI.ts | 10 +++++++--- src/apps/chatwoot/client/ContactConversationService.ts | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/apps/chatwoot/client/ContactAPI.ts b/src/apps/chatwoot/client/ContactAPI.ts index 537073e8..7f802bd1 100644 --- a/src/apps/chatwoot/client/ContactAPI.ts +++ b/src/apps/chatwoot/client/ContactAPI.ts @@ -96,18 +96,22 @@ export class ContactAPI { }; } - public updateCustomAttributes( + public async upsertCustomAttributes( contact: generic_id & contact, attributes: any, - ) { + ): Promise { + if (lodash.isEqual(attributes, contact.custom_attributes)) { + return false; + } const update: contact_update = { custom_attributes: { ...contact.custom_attributes, ...attributes }, }; - return this.accountAPI.contacts.update({ + await this.accountAPI.contacts.update({ id: contact.id, accountId: this.config.accountId, data: update, }); + return true; } public async create( diff --git a/src/apps/chatwoot/client/ContactConversationService.ts b/src/apps/chatwoot/client/ContactConversationService.ts index cfa8666b..ca0e1613 100644 --- a/src/apps/chatwoot/client/ContactConversationService.ts +++ b/src/apps/chatwoot/client/ContactConversationService.ts @@ -62,9 +62,9 @@ export class ContactConversationService { // Update custom attributes - always const attributes = await contactInfo.Attributes(); this.logger.info( - `Updating contact custom attributes for chat.id: ${chatId}, contact.id: ${contact.data.id}`, + `Updating if required contact custom attributes for chat.id: ${chatId}, contact.id: ${contact.data.id}`, ); - await this.contactAPI.updateCustomAttributes(contact.data, attributes); + await this.contactAPI.upsertCustomAttributes(contact.data, attributes); // Update Avatar if nothing, but keep the original one if any if (!contact.data.thumbnail) {