From d656727b7ab0e112dbce401c22ae3ef145a70799 Mon Sep 17 00:00:00 2001 From: pedro-php Date: Wed, 14 May 2025 16:13:57 -0300 Subject: [PATCH 1/2] lint changes --- src/api/controllers/health.controller.ts | 2 - .../whatsapp/whatsapp.baileys.service.ts | 63 +++++++++++-------- src/api/routes/health.router.ts | 18 +++--- src/api/routes/index.router.ts | 2 +- src/api/server.module.ts | 2 +- src/api/services/channel.service.ts | 2 +- 6 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/api/controllers/health.controller.ts b/src/api/controllers/health.controller.ts index 74f10f0b..0d4cebdd 100644 --- a/src/api/controllers/health.controller.ts +++ b/src/api/controllers/health.controller.ts @@ -1,6 +1,4 @@ import { WAMonitoringService } from '@api/services/monitor.service'; - -import { UnauthorizedException } from '../../exceptions'; import { PrismaRepository } from '../repository/repository.service'; export class HealthController { diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index edd61e0d..dc775a36 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -383,7 +383,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, ), ); @@ -1024,18 +1024,18 @@ 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) { @@ -1364,24 +1364,33 @@ export class BaileysStartupService extends ChannelStartupService { } } } - if (1/* this.localWebhook.enabled */) { - if (1/* isMedia && this.localWebhook.webhookBase64 */) { + if (this.localWebhook.enabled) { + if (isMedia && this.localWebhook.webhookBase64) { try { - let buffer : Buffer = null; - console.dir({received}, {depth: null}); - if ((received.message.stickerMessage && received.message.stickerMessage.url === 'https://web.whatsapp.net') - || (received.message.lottieStickerMessage && received.message.lottieStickerMessage.message.stickerMessage.url)) { /*Fixing broken URLs from sticker messages*/ - const newUrl = `https://mmg.whatsapp.net${received.message.lottieStickerMessage ? received.message.lottieStickerMessage.message.stickerMessage.directPath : received.message.stickerMessage.directPath }`; + let buffer: Buffer = null; + console.dir({ received }, { depth: null }); + if ( + (received.message.stickerMessage && + received.message.stickerMessage.url === 'https://web.whatsapp.net') || + (received.message.lottieStickerMessage && + received.message.lottieStickerMessage.message.stickerMessage.url) + ) { + /*Fixing broken URLs from sticker messages*/ + const newUrl = `https://mmg.whatsapp.net${received.message.lottieStickerMessage ? received.message.lottieStickerMessage.message.stickerMessage.directPath : received.message.stickerMessage.directPath}`; const stream = await downloadContentFromMessage( { - mediaKey: received.message?.stickerMessage?.mediaKey || received.message.lottieStickerMessage?.message?.stickerMessage?.mediaKey, - directPath: received.message?.stickerMessage?.directPath || received.message.lottieStickerMessage?.message?.stickerMessage?.directPath, - url: newUrl - }, + mediaKey: + received.message?.stickerMessage?.mediaKey || + received.message.lottieStickerMessage?.message?.stickerMessage?.mediaKey, + directPath: + received.message?.stickerMessage?.directPath || + received.message.lottieStickerMessage?.message?.stickerMessage?.directPath, + url: newUrl, + }, 'sticker', {}, - ) + ); const chunks = []; for await (const chunk of stream) { chunks.push(chunk); @@ -1406,7 +1415,7 @@ export class BaileysStartupService extends ChannelStartupService { } } - console.dir({webhookMessage: messageRaw}, {depth: null}) + console.dir({ webhookMessage: messageRaw }, { depth: null }); this.logger.log(messageRaw); this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw); @@ -1778,7 +1787,7 @@ export class BaileysStartupService extends ChannelStartupService { } if (events['messages.upsert']) { - const payload = events['messages.upsert'] + const payload = events['messages.upsert']; this.messageHandle['messages.upsert'](payload, settings); } @@ -2300,7 +2309,7 @@ export class BaileysStartupService extends ChannelStartupService { messageSent?.message?.documentMessage || messageSent?.message?.documentWithCaptionMessage || messageSent?.message?.ptvMessage || - messageSent?.message?.audioMessage || + messageSent?.message?.audioMessage || messageSent?.message?.lottieStickerMessage; if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot?.enabled && !isIntegration) { diff --git a/src/api/routes/health.router.ts b/src/api/routes/health.router.ts index 344bad29..83679452 100644 --- a/src/api/routes/health.router.ts +++ b/src/api/routes/health.router.ts @@ -1,18 +1,16 @@ -import { RequestHandler, Router } from "express"; -import { RouterBroker } from "../abstract/abstract.router"; -import { HttpStatus } from "./index.router"; -import { healthController } from "@api/server.module"; +import { healthController } from '@api/server.module'; +import { RouterBroker } from '../abstract/abstract.router'; +import { HttpStatus } from './index.router'; export class HealthRouter extends RouterBroker { constructor() { super(); - this.router - .get(this.routerPath('healthz', false), async (req, res) => { - await healthController.checkHealth(); - return res.status(HttpStatus.OK).json({msg: 'healthy'}); - }) + this.router.get(this.routerPath('healthz', false), async (req, res) => { + await healthController.checkHealth(); + return res.status(HttpStatus.OK).json({ msg: 'healthy' }); + }); } public readonly router: Router = Router(); -} \ No newline at end of file +} diff --git a/src/api/routes/index.router.ts b/src/api/routes/index.router.ts index fbd108e2..df85aa17 100644 --- a/src/api/routes/index.router.ts +++ b/src/api/routes/index.router.ts @@ -15,6 +15,7 @@ import { BusinessRouter } from './business.router'; import { CallRouter } from './call.router'; import { ChatRouter } from './chat.router'; import { GroupRouter } from './group.router'; +import { HealthRouter } from './health.router'; import { InstanceRouter } from './instance.router'; import { LabelRouter } from './label.router'; import { ProxyRouter } from './proxy.router'; @@ -22,7 +23,6 @@ import { MessageRouter } from './sendMessage.router'; import { SettingsRouter } from './settings.router'; import { TemplateRouter } from './template.router'; import { ViewsRouter } from './view.router'; -import { HealthRouter} from './health.router'; enum HttpStatus { OK = 200, diff --git a/src/api/server.module.ts b/src/api/server.module.ts index 49210529..95ec68ff 100644 --- a/src/api/server.module.ts +++ b/src/api/server.module.ts @@ -7,6 +7,7 @@ import { BusinessController } from './controllers/business.controller'; import { CallController } from './controllers/call.controller'; import { ChatController } from './controllers/chat.controller'; import { GroupController } from './controllers/group.controller'; +import { HealthController } from './controllers/health.controller'; import { InstanceController } from './controllers/instance.controller'; import { LabelController } from './controllers/label.controller'; import { ProxyController } from './controllers/proxy.controller'; @@ -40,7 +41,6 @@ import { WAMonitoringService } from './services/monitor.service'; import { ProxyService } from './services/proxy.service'; import { SettingsService } from './services/settings.service'; import { TemplateService } from './services/template.service'; -import { HealthController } from './controllers/health.controller'; const logger = new Logger('WA MODULE'); diff --git a/src/api/services/channel.service.ts b/src/api/services/channel.service.ts index 1c919c99..4754ac0e 100644 --- a/src/api/services/channel.service.ts +++ b/src/api/services/channel.service.ts @@ -553,7 +553,7 @@ export class ChannelStartupService { } // Limpa LottieStickerMessage - if(cleanedMessage.message.lottieStickerMessage) { + if (cleanedMessage.message.lottieStickerMessage) { cleanedMessage.message.lottieStickerMessage = {}; } From b8a0b71182d46e118fa6d8ec02b021648a8a33e2 Mon Sep 17 00:00:00 2001 From: pedro-php Date: Wed, 14 May 2025 16:18:09 -0300 Subject: [PATCH 2/2] hotfix_lint --- src/api/controllers/health.controller.ts | 1 + src/api/routes/health.router.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/api/controllers/health.controller.ts b/src/api/controllers/health.controller.ts index 0d4cebdd..88b6f5ca 100644 --- a/src/api/controllers/health.controller.ts +++ b/src/api/controllers/health.controller.ts @@ -1,4 +1,5 @@ import { WAMonitoringService } from '@api/services/monitor.service'; + import { PrismaRepository } from '../repository/repository.service'; export class HealthController { diff --git a/src/api/routes/health.router.ts b/src/api/routes/health.router.ts index 83679452..8b460158 100644 --- a/src/api/routes/health.router.ts +++ b/src/api/routes/health.router.ts @@ -1,4 +1,5 @@ import { healthController } from '@api/server.module'; +import { Router } from 'express'; import { RouterBroker } from '../abstract/abstract.router'; import { HttpStatus } from './index.router';