Skip to content

Commit bee309c

Browse files
committed
fix: streamline message handling logic and improve cache management in BaileysStartupService
1 parent 92c2ace commit bee309c

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,12 +1148,7 @@ export class BaileysStartupService extends ChannelStartupService {
11481148
}
11491149
}
11501150

1151-
if (
1152-
(type !== 'notify' && type !== 'append') ||
1153-
editedMessage ||
1154-
received.message?.pollUpdateMessage ||
1155-
!received?.message
1156-
) {
1151+
if ((type !== 'notify' && type !== 'append') || editedMessage || !received?.message) {
11571152
continue;
11581153
}
11591154

@@ -1447,18 +1442,18 @@ export class BaileysStartupService extends ChannelStartupService {
14471442
continue;
14481443
}
14491444

1450-
if (update.message !== null && update.status === undefined) continue;
1445+
if (update.message === null && update.status === undefined) continue;
14511446

14521447
const updateKey = `${this.instance.id}_${key.id}_${update.status}`;
14531448

14541449
const cached = await this.baileysCache.get(updateKey);
14551450

1456-
if (cached) {
1451+
if (cached && update.messageTimestamp == cached.messageTimestamp) {
14571452
this.logger.info(`Update Message duplicated ignored [avoid deadlock]: ${updateKey}`);
14581453
continue;
14591454
}
14601455

1461-
await this.baileysCache.set(updateKey, true, 30 * 60);
1456+
await this.baileysCache.set(updateKey, update.messageTimestamp, 30 * 60);
14621457

14631458
if (status[update.status] === 'READ' && key.fromMe) {
14641459
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
@@ -1489,7 +1484,7 @@ export class BaileysStartupService extends ChannelStartupService {
14891484
remoteJid: key?.remoteJid,
14901485
fromMe: key.fromMe,
14911486
participant: key?.participant,
1492-
status: status[update.status] ?? 'DELETED',
1487+
status: status[update.status] ?? 'SERVER_ACK',
14931488
pollUpdates,
14941489
instanceId: this.instanceId,
14951490
};

0 commit comments

Comments
 (0)