From 7e4dbfdd7e108d9a4d8437f4857997def278823a Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Thu, 31 Aug 2023 18:24:30 -0300 Subject: [PATCH] fix: Added log when send event to rabbitMQ and Websocket --- src/libs/amqp.server.ts | 1 - .../controllers/instance.controller.ts | 1 - src/whatsapp/services/whatsapp.service.ts | 38 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/libs/amqp.server.ts b/src/libs/amqp.server.ts index 172d76a7..18b82c52 100644 --- a/src/libs/amqp.server.ts +++ b/src/libs/amqp.server.ts @@ -43,7 +43,6 @@ export const getAMQP = (): amqp.Channel | null => { }; export const initQueues = (instanceName: string, events: string[]) => { - console.log('initQueues', instanceName, events); if (!events || !events.length) return; const queues = events.map((event) => { diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index 257d5f05..8d0e21ca 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -5,7 +5,6 @@ import EventEmitter2 from 'eventemitter2'; import { ConfigService, HttpServer } from '../../config/env.config'; import { Logger } from '../../config/logger.config'; import { BadRequestException, InternalServerErrorException } from '../../exceptions'; -import { initQueues } from '../../libs/amqp.server'; import { RedisCache } from '../../libs/redis.client'; import { InstanceDto } from '../dto/instance.dto'; import { RepositoryBroker } from '../repository/repository.manager'; diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index f5e2c619..2e5e79f6 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -688,6 +688,25 @@ export class WAStartupService { } amqp.publish(exchangeName, event, Buffer.from(JSON.stringify(message))); + + if (this.configService.get('LOG').LEVEL.includes('WEBHOOKS')) { + const logData = { + local: WAStartupService.name + '.sendData-RabbitMQ', + event, + instance: this.instance.name, + data, + server_url: serverUrl, + apikey: (expose && instanceApikey) || null, + date_time: now, + sender: this.wuid, + }; + + if (expose && instanceApikey) { + logData['apikey'] = instanceApikey; + } + + this.logger.log(logData); + } } } } @@ -713,6 +732,25 @@ export class WAStartupService { this.logger.verbose('Sending data to socket.io in channel: ' + this.instance.name); io.of(`/${this.instance.name}`).emit(event, message); + + if (this.configService.get('LOG').LEVEL.includes('WEBHOOKS')) { + const logData = { + local: WAStartupService.name + '.sendData-Websocket', + event, + instance: this.instance.name, + data, + server_url: serverUrl, + apikey: (expose && instanceApikey) || null, + date_time: now, + sender: this.wuid, + }; + + if (expose && instanceApikey) { + logData['apikey'] = instanceApikey; + } + + this.logger.log(logData); + } } }