Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
const client = await this.clientCw(instance);

if (!client) {
Expand All @@ -370,6 +370,7 @@ export class ChatwootService {

return contact;
} catch (error) {
this.logger.error(`[WIDGET-WORKS] updateContact failed: ${error?.message || error}`);
return null;
}
}
Expand Down Expand Up @@ -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 {
Expand Down