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 @@ -5,6 +5,7 @@
* [WIDGET-WORKS] Fix `PrismaClientValidationError` in `messages.update` (missing `Message` relation) by guarding `messageUpdate.create` calls.
* [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] Cache sent message keys in Baileys so WhatsApp echoes are ignored (prevents Chatwoot automation duplicates when `isIntegration=true`).
* [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.

Expand Down
10 changes: 10 additions & 0 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,16 @@ export class BaileysStartupService extends ChannelStartupService {

const messageRaw = this.prepareMessage(messageSent);

// [WIDGET-WORKS] Cache sent message key so messages.upsert treats the WhatsApp echo as duplicate
try {
const messageKey = `${this.instance.id}_${messageRaw.key.id}`;
await this.baileysCache.set(messageKey, true, 5 * 60);
} catch (error) {
this.logger.warn(
`[WIDGET-WORKS] Failed to cache sent message ${messageRaw?.key?.id ?? 'unknown'}: ${error?.message}`,
);
}

const isMedia =
messageSent?.message?.imageMessage ||
messageSent?.message?.videoMessage ||
Expand Down