From 55822f9443ae5a3200e122083d97ff84227fd58c Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Wed, 17 Sep 2025 14:30:27 -0300 Subject: [PATCH] style: improve code formatting for better readability in WhatsApp service files --- .../channel/meta/whatsapp.business.service.ts | 8 ++-- .../whatsapp/whatsapp.baileys.service.ts | 43 +++++++++++-------- src/utils/getConversationMessage.ts | 14 +++--- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/api/integrations/channel/meta/whatsapp.business.service.ts b/src/api/integrations/channel/meta/whatsapp.business.service.ts index 0b76b87a..66847f82 100644 --- a/src/api/integrations/channel/meta/whatsapp.business.service.ts +++ b/src/api/integrations/channel/meta/whatsapp.business.service.ts @@ -463,7 +463,8 @@ export class BusinessStartupService extends ChannelStartupService { this.logger?.info?.('Video upload attempted but is disabled by configuration.'); return { success: false, - message: 'Video upload is currently disabled. Please contact support if you need this feature enabled.', + message: + 'Video upload is currently disabled. Please contact support if you need this feature enabled.', }; } @@ -1213,8 +1214,9 @@ export class BusinessStartupService extends ChannelStartupService { const token = this.token; const headers = { Authorization: `Bearer ${token}` }; - const url = `${this.configService.get('WA_BUSINESS').URL}/${this.configService.get('WA_BUSINESS').VERSION - }/${this.number}/media`; + const url = `${this.configService.get('WA_BUSINESS').URL}/${ + this.configService.get('WA_BUSINESS').VERSION + }/${this.number}/media`; const res = await axios.post(url, formData, { headers }); return res.data.id; diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index c3f7d3d1..f1dd2b3a 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -381,7 +381,7 @@ export class BaileysStartupService extends ChannelStartupService { qrcodeTerminal.generate(qr, { small: true }, (qrcode) => this.logger.log( `\n{ instance: ${this.instance.name} pairingCode: ${this.instance.qrcode.pairingCode}, qrcodeCount: ${this.instance.qrcode.count} }\n` + - qrcode, + qrcode, ), ); @@ -978,16 +978,16 @@ export class BaileysStartupService extends ChannelStartupService { const messagesRepository: Set = new Set( chatwootImport.getRepositoryMessagesCache(instance) ?? - ( - await this.prismaRepository.message.findMany({ - select: { key: true }, - where: { instanceId: this.instanceId }, - }) - ).map((message) => { - const key = message.key as { id: string }; + ( + await this.prismaRepository.message.findMany({ + select: { key: true }, + where: { instanceId: this.instanceId }, + }) + ).map((message) => { + const key = message.key as { id: string }; - return key.id; - }), + return key.id; + }), ); if (chatwootImport.getRepositoryMessagesCache(instance) === null) { @@ -4726,12 +4726,7 @@ export class BaileysStartupService extends ChannelStartupService { } public async fetchMessages(query: Query) { - const keyFilters = query?.where?.key as { - id?: string; - fromMe?: boolean; - remoteJid?: string; - participants?: string; - }; + const keyFilters = query?.where?.key as ExtendedIMessageKey; const timestampFilter = {}; if (query?.where?.messageTimestamp) { @@ -4754,7 +4749,13 @@ export class BaileysStartupService extends ChannelStartupService { keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {}, keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {}, keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {}, - keyFilters?.participants ? { key: { path: ['participants'], equals: keyFilters?.participants } } : {}, + keyFilters?.participant ? { key: { path: ['participant'], equals: keyFilters?.participant } } : {}, + { + OR: [ + keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {}, + keyFilters?.senderPn ? { key: { path: ['senderPn'], equals: keyFilters?.senderPn } } : {}, + ], + }, ], }, }); @@ -4778,7 +4779,13 @@ export class BaileysStartupService extends ChannelStartupService { keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {}, keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {}, keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {}, - keyFilters?.participants ? { key: { path: ['participants'], equals: keyFilters?.participants } } : {}, + keyFilters?.participant ? { key: { path: ['participant'], equals: keyFilters?.participant } } : {}, + { + OR: [ + keyFilters?.remoteJid ? { key: { path: ['remoteJid'], equals: keyFilters?.remoteJid } } : {}, + keyFilters?.senderPn ? { key: { path: ['senderPn'], equals: keyFilters?.senderPn } } : {}, + ], + }, ], }, orderBy: { messageTimestamp: 'desc' }, diff --git a/src/utils/getConversationMessage.ts b/src/utils/getConversationMessage.ts index a34695e7..eca23b45 100644 --- a/src/utils/getConversationMessage.ts +++ b/src/utils/getConversationMessage.ts @@ -38,14 +38,16 @@ const getTypeMessage = (msg: any) => { ? `videoMessage|${mediaId}${msg?.message?.videoMessage?.caption ? `|${msg?.message?.videoMessage?.caption}` : ''}` : undefined, documentMessage: msg?.message?.documentMessage - ? `documentMessage|${mediaId}${msg?.message?.documentMessage?.caption ? `|${msg?.message?.documentMessage?.caption}` : '' - }` + ? `documentMessage|${mediaId}${ + msg?.message?.documentMessage?.caption ? `|${msg?.message?.documentMessage?.caption}` : '' + }` : undefined, documentWithCaptionMessage: msg?.message?.documentWithCaptionMessage?.message?.documentMessage - ? `documentWithCaptionMessage|${mediaId}${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption - ? `|${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption}` - : '' - }` + ? `documentWithCaptionMessage|${mediaId}${ + msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption + ? `|${msg?.message?.documentWithCaptionMessage?.message?.documentMessage?.caption}` + : '' + }` : undefined, externalAdReplyBody: msg?.contextInfo?.externalAdReply?.body ? `externalAdReplyBody|${msg.contextInfo.externalAdReply.body}`