From e51b6e9270bc76a77f9bd283cb9f5926eb9ff060 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Mon, 3 Feb 2025 17:19:07 -0300 Subject: [PATCH] fix: improve message deduplication and edited message handling in Baileys service - Refactor edited message detection logic - Prevent duplicate message processing for edited messages - Optimize message key caching mechanism --- .gitignore | 2 ++ .../channel/whatsapp/whatsapp.baileys.service.ts | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a8226ede..1cecfa98 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ /dist /node_modules +.cursor* + /Docker/.env .vscode diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 5f006a2c..9f716545 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1128,9 +1128,10 @@ export class BaileysStartupService extends ChannelStartupService { } } + const editedMessage = + received?.message?.protocolMessage || received?.message?.editedMessage?.message?.protocolMessage; + if (received.message?.protocolMessage?.editedMessage || received.message?.editedMessage?.message) { - const editedMessage = - received.message?.protocolMessage || received.message?.editedMessage?.message?.protocolMessage; if (editedMessage) { if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled) this.chatwootService.eventWhatsapp( @@ -1165,7 +1166,7 @@ export class BaileysStartupService extends ChannelStartupService { const messageKey = `${this.instance.id}_${received.key.id}`; const cached = await this.baileysCache.get(messageKey); - if (cached) { + if (cached && !editedMessage) { this.logger.info(`Message duplicated ignored: ${received.key.id}`); continue; }