From 0f2498bbaad0c3415ce3fdd24d088f29244f1ef2 Mon Sep 17 00:00:00 2001 From: Jesus Date: Tue, 7 Jan 2025 08:50:34 +0100 Subject: [PATCH] Fix prettier errors --- src/api/controllers/proxy.controller.ts | 5 ++- src/api/dto/instance.dto.ts | 9 +++++- .../channel/meta/whatsapp.business.service.ts | 31 ++++++++++--------- .../event/webhook/webhook.router.ts | 5 ++- src/api/routes/instance.router.ts | 5 ++- src/api/routes/template.router.ts | 5 ++- src/api/services/monitor.service.ts | 29 +++++++++-------- src/cache/cacheengine.ts | 5 ++- src/cache/localcache.ts | 5 ++- src/cache/rediscache.ts | 5 ++- src/utils/getConversationMessage.ts | 4 +-- 11 files changed, 71 insertions(+), 37 deletions(-) diff --git a/src/api/controllers/proxy.controller.ts b/src/api/controllers/proxy.controller.ts index 3fcde3bb9..fac003759 100644 --- a/src/api/controllers/proxy.controller.ts +++ b/src/api/controllers/proxy.controller.ts @@ -10,7 +10,10 @@ import axios from 'axios'; const logger = new Logger('ProxyController'); export class ProxyController { - constructor(private readonly proxyService: ProxyService, private readonly waMonitor: WAMonitoringService) {} + constructor( + private readonly proxyService: ProxyService, + private readonly waMonitor: WAMonitoringService, + ) {} public async createProxy(instance: InstanceDto, data: ProxyDto) { if (!this.waMonitor.waInstances[instance.instanceName]) { diff --git a/src/api/dto/instance.dto.ts b/src/api/dto/instance.dto.ts index 0f61a9a32..66d230336 100644 --- a/src/api/dto/instance.dto.ts +++ b/src/api/dto/instance.dto.ts @@ -24,7 +24,14 @@ export class InstanceDto extends IntegrationDto { proxyProtocol?: string; proxyUsername?: string; proxyPassword?: string; - webhook?: { enabled?: boolean; events?: string[]; headers?: JsonValue; url?: string; byEvents?: boolean; base64?: boolean; }; + webhook?: { + enabled?: boolean; + events?: string[]; + headers?: { [key: string]: string }; + url?: string; + byEvents?: boolean; + base64?: boolean; + }; chatwootAccountId?: string; chatwootConversationPending?: boolean; chatwootAutoCreate?: boolean; diff --git a/src/api/integrations/channel/meta/whatsapp.business.service.ts b/src/api/integrations/channel/meta/whatsapp.business.service.ts index b038b8dee..54c0c73a4 100644 --- a/src/api/integrations/channel/meta/whatsapp.business.service.ts +++ b/src/api/integrations/channel/meta/whatsapp.business.service.ts @@ -330,13 +330,17 @@ export class BusinessStartupService extends ChannelStartupService { const buffer = await axios.get(result.data.url, { headers, responseType: 'arraybuffer' }); - const mediaType = message.messages[0].document - ? 'document' - : message.messages[0].image - ? 'image' - : message.messages[0].audio - ? 'audio' - : 'video'; + let mediaType; + + if (message.messages[0].document) { + mediaType = 'document'; + } else if (message.messages[0].image) { + mediaType = 'image'; + } else if (message.messages[0].audio) { + mediaType = 'audio'; + } else { + mediaType = 'video'; + } const mimetype = result.data?.mime_type || result.headers['content-type']; @@ -797,7 +801,7 @@ export class BusinessStartupService extends ChannelStartupService { } if (message['media']) { const isImage = message['mimetype']?.startsWith('image/'); - + content = { messaging_product: 'whatsapp', recipient_type: 'individual', @@ -812,7 +816,7 @@ export class BusinessStartupService extends ChannelStartupService { }; quoted ? (content.context = { message_id: quoted.id }) : content; return await this.post(content, 'messages'); - } + } if (message['audio']) { content = { messaging_product: 'whatsapp', @@ -1100,11 +1104,10 @@ export class BusinessStartupService extends ChannelStartupService { if (file?.buffer) { mediaData.audio = file.buffer.toString('base64'); - } - else if(isURL(mediaData.audio)){ - mediaData.audio = mediaData.audio - } - else { + } else if (isURL(mediaData.audio)) { + // DO NOTHING + // mediaData.audio = mediaData.audio; + } else { console.error('El archivo no tiene buffer o file es undefined'); throw new Error('File or buffer is undefined'); } diff --git a/src/api/integrations/event/webhook/webhook.router.ts b/src/api/integrations/event/webhook/webhook.router.ts index 5193bec58..149f940b3 100644 --- a/src/api/integrations/event/webhook/webhook.router.ts +++ b/src/api/integrations/event/webhook/webhook.router.ts @@ -8,7 +8,10 @@ import { instanceSchema, webhookSchema } from '@validate/validate.schema'; import { RequestHandler, Router } from 'express'; export class WebhookRouter extends RouterBroker { - constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) { + constructor( + readonly configService: ConfigService, + ...guards: RequestHandler[] + ) { super(); this.router .post(this.routerPath('set'), ...guards, async (req, res) => { diff --git a/src/api/routes/instance.router.ts b/src/api/routes/instance.router.ts index 2bf7f967c..dd990c3b8 100644 --- a/src/api/routes/instance.router.ts +++ b/src/api/routes/instance.router.ts @@ -8,7 +8,10 @@ import { RequestHandler, Router } from 'express'; import { HttpStatus } from './index.router'; export class InstanceRouter extends RouterBroker { - constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) { + constructor( + readonly configService: ConfigService, + ...guards: RequestHandler[] + ) { super(); this.router .post('/create', ...guards, async (req, res) => { diff --git a/src/api/routes/template.router.ts b/src/api/routes/template.router.ts index 67607dc8e..b77b7d834 100644 --- a/src/api/routes/template.router.ts +++ b/src/api/routes/template.router.ts @@ -9,7 +9,10 @@ import { RequestHandler, Router } from 'express'; import { HttpStatus } from './index.router'; export class TemplateRouter extends RouterBroker { - constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) { + constructor( + readonly configService: ConfigService, + ...guards: RequestHandler[] + ) { super(); this.router .post(this.routerPath('create'), ...guards, async (req, res) => { diff --git a/src/api/services/monitor.service.ts b/src/api/services/monitor.service.ts index cd2025063..ecadeb736 100644 --- a/src/api/services/monitor.service.ts +++ b/src/api/services/monitor.service.ts @@ -42,20 +42,23 @@ export class WAMonitoringService { public delInstanceTime(instance: string) { const time = this.configService.get('DEL_INSTANCE'); if (typeof time === 'number' && time > 0) { - setTimeout(async () => { - if (this.waInstances[instance]?.connectionStatus?.state !== 'open') { - if (this.waInstances[instance]?.connectionStatus?.state === 'connecting') { - if ((await this.waInstances[instance].integration) === Integration.WHATSAPP_BAILEYS) { - await this.waInstances[instance]?.client?.logout('Log out instance: ' + instance); - this.waInstances[instance]?.client?.ws?.close(); - this.waInstances[instance]?.client?.end(undefined); + setTimeout( + async () => { + if (this.waInstances[instance]?.connectionStatus?.state !== 'open') { + if (this.waInstances[instance]?.connectionStatus?.state === 'connecting') { + if ((await this.waInstances[instance].integration) === Integration.WHATSAPP_BAILEYS) { + await this.waInstances[instance]?.client?.logout('Log out instance: ' + instance); + this.waInstances[instance]?.client?.ws?.close(); + this.waInstances[instance]?.client?.end(undefined); + } + this.eventEmitter.emit('remove.instance', instance, 'inner'); + } else { + this.eventEmitter.emit('remove.instance', instance, 'inner'); } - this.eventEmitter.emit('remove.instance', instance, 'inner'); - } else { - this.eventEmitter.emit('remove.instance', instance, 'inner'); } - } - }, 1000 * 60 * time); + }, + 1000 * 60 * time, + ); } } @@ -219,7 +222,7 @@ export class WAMonitoringService { id: data.instanceId, name: data.instanceName, connectionStatus: - data.integration && data.integration === Integration.WHATSAPP_BAILEYS ? 'close' : data.status ?? 'open', + data.integration && data.integration === Integration.WHATSAPP_BAILEYS ? 'close' : (data.status ?? 'open'), number: data.number, integration: data.integration || Integration.WHATSAPP_BAILEYS, token: data.hash, diff --git a/src/cache/cacheengine.ts b/src/cache/cacheengine.ts index e09703311..cc4a1b9c4 100644 --- a/src/cache/cacheengine.ts +++ b/src/cache/cacheengine.ts @@ -10,7 +10,10 @@ const logger = new Logger('CacheEngine'); export class CacheEngine { private engine: ICache; - constructor(private readonly configService: ConfigService, module: string) { + constructor( + private readonly configService: ConfigService, + module: string, + ) { const cacheConf = configService.get('CACHE'); if (cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') { diff --git a/src/cache/localcache.ts b/src/cache/localcache.ts index d926bdd9b..2aa2007ea 100644 --- a/src/cache/localcache.ts +++ b/src/cache/localcache.ts @@ -9,7 +9,10 @@ export class LocalCache implements ICache { private conf: CacheConfLocal; static localCache = new NodeCache(); - constructor(private readonly configService: ConfigService, private readonly module: string) { + constructor( + private readonly configService: ConfigService, + private readonly module: string, + ) { this.conf = this.configService.get('CACHE')?.LOCAL; } diff --git a/src/cache/rediscache.ts b/src/cache/rediscache.ts index 67c21c378..1ec67e760 100644 --- a/src/cache/rediscache.ts +++ b/src/cache/rediscache.ts @@ -11,7 +11,10 @@ export class RedisCache implements ICache { private client: RedisClientType; private conf: CacheConfRedis; - constructor(private readonly configService: ConfigService, private readonly module: string) { + constructor( + private readonly configService: ConfigService, + private readonly module: string, + ) { this.conf = this.configService.get('CACHE')?.REDIS; this.client = redisClient.getConnection(); } diff --git a/src/utils/getConversationMessage.ts b/src/utils/getConversationMessage.ts index 2bd13b763..b2522ab05 100644 --- a/src/utils/getConversationMessage.ts +++ b/src/utils/getConversationMessage.ts @@ -23,8 +23,8 @@ const getTypeMessage = (msg: any) => { audioMessage: msg?.message?.speechToText ? msg?.message?.speechToText : msg?.message?.audioMessage - ? `audioMessage|${mediaId}` - : undefined, + ? `audioMessage|${mediaId}` + : undefined, imageMessage: msg?.message?.imageMessage ? `imageMessage|${mediaId}${msg?.message?.imageMessage?.caption ? `|${msg?.message?.imageMessage?.caption}` : ''}` : undefined,