diff --git a/CHANGELOG.md b/CHANGELOG.md index c443cfe7..d4e1b87f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.5.4 (develop) + +### Fixed + +* Baileys logger typing issue resolved +* Solved problem with duplicate messages in chatwoot + # 1.5.3 (2023-10-06 18:55) ### Feature diff --git a/Dockerfile b/Dockerfile index e5c218cc..dee414d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:20.7.0-alpine -LABEL version="1.5.3" description="Api to control whatsapp features through http requests." +LABEL version="1.5.4" description="Api to control whatsapp features through http requests." LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" LABEL contact="contato@agenciadgcode.com" diff --git a/package.json b/package.json index 16c7466d..e00f1e39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "evolution-api", - "version": "1.5.3", + "version": "1.5.4", "description": "Rest api for communication with WhatsApp", "main": "./dist/src/main.js", "scripts": { diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index c58ff582..5f9235ac 100644 --- a/src/docs/swagger.yaml +++ b/src/docs/swagger.yaml @@ -25,7 +25,7 @@ info: [![Run in Postman](https://run.pstmn.io/button.svg)](https://god.gw.postman.com/run-collection/26869335-5546d063-156b-4529-915f-909dd628c090?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D26869335-5546d063-156b-4529-915f-909dd628c090%26entityType%3Dcollection%26workspaceId%3D339a4ee7-378b-45c9-b5b8-fd2c0a9c2442) - version: 1.5.2 + version: 1.5.4 contact: name: DavidsonGomes email: contato@agenciadgcode.com diff --git a/src/whatsapp/controllers/views.controller.ts b/src/whatsapp/controllers/views.controller.ts index e775b960..7e15dfe7 100644 --- a/src/whatsapp/controllers/views.controller.ts +++ b/src/whatsapp/controllers/views.controller.ts @@ -1,15 +1,21 @@ import { Request, Response } from 'express'; -import { ConfigService } from '../../config/env.config'; +import { Auth, ConfigService, HttpServer } from '../../config/env.config'; import { HttpStatus } from '../routers/index.router'; import { WAMonitoringService } from '../services/monitor.service'; export class ViewsController { - constructor(private readonly waMonit: WAMonitoringService, private readonly configService: ConfigService) {} + constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {} public async manager(request: Request, response: Response) { try { - return response.status(HttpStatus.OK).render('manager'); + const token = this.configService.get('AUTHENTICATION').API_KEY.KEY; + const port = this.configService.get('SERVER').PORT; + + const instances = await this.waMonitor.instanceInfo(); + + console.log('INSTANCES: ', instances); + return response.status(HttpStatus.OK).render('manager', { token, port, instances }); } catch (error) { console.log('ERROR: ', error); } diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index 6c145ea2..b19fa31f 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -914,7 +914,7 @@ export class ChatwootService { }, }; - await waInstance?.audioWhatsapp(data); + await waInstance?.audioWhatsapp(data, true); this.logger.verbose('audio sent'); return; @@ -939,7 +939,7 @@ export class ChatwootService { data.mediaMessage.caption = caption; } - await waInstance?.mediaMessage(data); + await waInstance?.mediaMessage(data, true); this.logger.verbose('media sent'); return; @@ -1074,7 +1074,7 @@ export class ChatwootService { }, }; - await waInstance?.textMessage(data); + await waInstance?.textMessage(data, true); } } } diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 56e0bc64..fdd028c0 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -33,6 +33,7 @@ import makeWASocket, { WAMessageUpdate, WASocket, } from '@whiskeysockets/baileys'; +import MAIN_LOGGER from '@whiskeysockets/baileys/lib/Utils/logger'; import axios from 'axios'; import { exec, execSync } from 'child_process'; import { arrayUnique, isBase64, isURL } from 'class-validator'; @@ -131,6 +132,8 @@ import { ChatwootService } from './chatwoot.service'; //import { SocksProxyAgent } from './socks-proxy-agent'; import { TypebotService } from './typebot.service'; +const logger = MAIN_LOGGER.child({}); + export class WAStartupService { constructor( private readonly configService: ConfigService, @@ -1542,7 +1545,7 @@ export class WAStartupService { 'buffer', {}, { - logger: P({ level: 'error' }), + logger: logger, reuploadRequest: this.client.updateMediaMessage, }, ); @@ -2061,7 +2064,12 @@ export class WAStartupService { } } - private async sendMessageWithTyping(number: string, message: T, options?: Options) { + private async sendMessageWithTyping( + number: string, + message: T, + options?: Options, + isChatwoot = false, + ) { this.logger.verbose('Sending message with typing'); this.logger.verbose(`Check if number "${number}" is WhatsApp`); @@ -2219,7 +2227,7 @@ export class WAStartupService { this.logger.verbose('Sending data to webhook in event SEND_MESSAGE'); await this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw); - if (this.localChatwoot.enabled) { + if (this.localChatwoot.enabled && !isChatwoot) { this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw); } @@ -2244,7 +2252,7 @@ export class WAStartupService { } // Send Message Controller - public async textMessage(data: SendTextDto) { + public async textMessage(data: SendTextDto, isChatwoot = false) { this.logger.verbose('Sending text message'); return await this.sendMessageWithTyping( data.number, @@ -2252,6 +2260,7 @@ export class WAStartupService { conversation: data.textMessage.text, }, data?.options, + isChatwoot, ); } @@ -2528,11 +2537,11 @@ export class WAStartupService { return result; } - public async mediaMessage(data: SendMediaDto) { + public async mediaMessage(data: SendMediaDto, isChatwoot = false) { this.logger.verbose('Sending media message'); const generate = await this.prepareMediaMessage(data.mediaMessage); - return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options); + return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot); } public async processAudio(audio: string, number: string) { @@ -2589,7 +2598,7 @@ export class WAStartupService { }); } - public async audioWhatsapp(data: SendAudioDto) { + public async audioWhatsapp(data: SendAudioDto, isChatwoot = false) { this.logger.verbose('Sending audio whatsapp'); if (!data.options?.encoding && data.options?.encoding !== false) { @@ -2608,6 +2617,7 @@ export class WAStartupService { mimetype: 'audio/mp4', }, { presence: 'recording', delay: data?.options?.delay }, + isChatwoot, ); fs.unlinkSync(convert); @@ -2629,6 +2639,7 @@ export class WAStartupService { mimetype: 'audio/ogg; codecs=opus', }, { presence: 'recording', delay: data?.options?.delay }, + isChatwoot, ); } diff --git a/views/manager-wip.hbs b/views/manager-wip.hbs new file mode 100644 index 00000000..59b0cd0f --- /dev/null +++ b/views/manager-wip.hbs @@ -0,0 +1,110 @@ + + + + + + + + + + + Instance Manager + + + +
+ + + + + + + + + + + + + + + + {{#each instances}} + + + + + + + {{/each}} + +
Nome da InstânciaStatusAPI KeyAções
{{this.instance.instanceName}}{{this.instance.status}}{{this.instance.apikey}} + + +
+
+ + + + + + + + + + + + \ No newline at end of file diff --git a/views/manager.hbs b/views/manager.hbs index 5414bdf1..57d5fca4 100644 --- a/views/manager.hbs +++ b/views/manager.hbs @@ -11,7 +11,7 @@ - +