Skip to content

Commit bb0ff85

Browse files
chore(whatsapp): remove raw upsert logging and centralize cache key
1 parent 24e6695 commit bb0ff85

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,10 @@ export class BaileysStartupService extends ChannelStartupService {
553553
}
554554
}
555555

556+
private getUpsertEmittedCacheKey(messageId: string) {
557+
return `upsert_emitted_${this.instanceId}_${messageId}`;
558+
}
559+
556560
private async defineAuthState() {
557561
const db = this.configService.get<Database>('DATABASE');
558562
const cache = this.configService.get<CacheConf>('CACHE');
@@ -1477,12 +1481,10 @@ export class BaileysStartupService extends ChannelStartupService {
14771481
if (messageRaw.key.remoteJid?.includes('@lid') && messageRaw.key.remoteJidAlt) {
14781482
messageRaw.key.remoteJid = messageRaw.key.remoteJidAlt;
14791483
}
1480-
console.log(messageRaw);
1481-
14821484
await this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
14831485

14841486
if (messageRaw.messageType === 'audioMessage' && !messageRaw.key.fromMe && messageRaw.key.id) {
1485-
await this.baileysCache.set(`upsert_emitted_${this.instanceId}_${messageRaw.key.id}`, true, 60 * 10);
1487+
await this.baileysCache.set(this.getUpsertEmittedCacheKey(messageRaw.key.id), true, 60 * 10);
14861488
}
14871489

14881490
await chatbotController.emit({
@@ -1654,7 +1656,7 @@ export class BaileysStartupService extends ChannelStartupService {
16541656
}
16551657

16561658
if (!key.fromMe && findMessage.messageType === 'audioMessage' && key.id) {
1657-
const upsertCacheKey = `upsert_emitted_${this.instanceId}_${key.id}`;
1659+
const upsertCacheKey = this.getUpsertEmittedCacheKey(key.id);
16581660
const alreadyEmitted = await this.baileysCache.get(upsertCacheKey);
16591661

16601662
if (!alreadyEmitted) {

0 commit comments

Comments
 (0)