From 95907b3cea582d6638d714dce4fe3379e12a3bfa Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Sun, 28 Apr 2024 09:47:06 -0300 Subject: [PATCH] v 1.7.4 --- CHANGELOG.md | 2 +- Dockerfile | 2 +- package.json | 2 +- .../channels/whatsapp.baileys.service.ts | 134 +----------------- src/docs/swagger.yaml | 2 +- 5 files changed, 7 insertions(+), 135 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c28267f3..fc595045b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.7.4 (develop) +# 1.7.4 (2024-04-28 09:46) ### Fixed * Adjusts in proxy on fetchAgent diff --git a/Dockerfile b/Dockerfile index a5e5c8b20..51955b71c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:20.7.0-alpine AS builder -LABEL version="1.7.3" description="Api to control whatsapp features through http requests." +LABEL version="1.7.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 f0b252a71..03ce55e2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "evolution-api", - "version": "1.7.3", + "version": "1.7.4", "description": "Rest api for communication with WhatsApp", "main": "./dist/src/main.js", "scripts": { diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index b1f961a04..7e2f8d881 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -40,7 +40,7 @@ import makeWASocket, { import { Label } from 'baileys/lib/Types/Label'; import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation'; import { exec } from 'child_process'; -import { arrayUnique, isBase64, isURL } from 'class-validator'; +import { isBase64, isURL } from 'class-validator'; import EventEmitter2 from 'eventemitter2'; // import ffmpeg from 'fluent-ffmpeg'; import fs, { existsSync, readFileSync } from 'fs'; @@ -97,7 +97,6 @@ import { MediaMessage, Options, SendAudioDto, - SendButtonDto, SendContactDto, SendListDto, SendLocationDto, @@ -2207,15 +2206,6 @@ export class BaileysStartupService extends ChannelStartupService { mimetype = response.headers['content-type']; } - // if (isURL(mediaMessage.media)) { - // const response = await axios.get(mediaMessage.media, { responseType: 'arraybuffer' }); - - // mimetype = response.headers['content-type']; - // console.log('mediaMessage.mimetype2', mimetype); - // } else { - // mimetype = getMIMEType(mediaMessage.fileName); - // console.log('mediaMessage.mimetype3', mimetype); - // } } this.logger.verbose('Mimetype: ' + mimetype); @@ -2330,82 +2320,6 @@ export class BaileysStartupService extends ChannelStartupService { return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot); } - // public async processAudio(audio: string, number: string) { - // this.logger.verbose('Processing audio'); - // let tempAudioPath: string; - // let outputAudio: string; - - // number = number.replace(/\D/g, ''); - // const hash = `${number}-${new Date().getTime()}`; - // this.logger.verbose('Hash to audio name: ' + hash); - - // if (isURL(audio)) { - // this.logger.verbose('Audio is url'); - - // outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`; - // tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`; - - // this.logger.verbose('Output audio path: ' + outputAudio); - // this.logger.verbose('Temp audio path: ' + tempAudioPath); - - // const timestamp = new Date().getTime(); - // const url = `${audio}?timestamp=${timestamp}`; - - // this.logger.verbose('Including timestamp in url: ' + url); - - // let config: any = { - // responseType: 'arraybuffer', - // }; - - // if (this.localProxy.enabled) { - // config = { - // ...config, - // httpsAgent: makeProxyAgent(this.localProxy.proxy), - // }; - // } - - // const response = await axios.get(url, config); - // this.logger.verbose('Getting audio from url'); - - // fs.writeFileSync(tempAudioPath, response.data); - // } else { - // this.logger.verbose('Audio is base64'); - - // outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`; - // tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`; - - // this.logger.verbose('Output audio path: ' + outputAudio); - // this.logger.verbose('Temp audio path: ' + tempAudioPath); - - // const audioBuffer = Buffer.from(audio, 'base64'); - // fs.writeFileSync(tempAudioPath, audioBuffer); - // this.logger.verbose('Temp audio created'); - // } - - // this.logger.verbose('Converting audio to mp4'); - // return new Promise((resolve, reject) => { - // // This fix was suggested by @PurpShell - // ffmpeg.setFfmpegPath(ffmpegPath.path); - - // ffmpeg() - // .input(tempAudioPath) - // .outputFormat('ogg') - // .noVideo() - // .audioCodec('libopus') - // .save(outputAudio) - // .on('error', function (error) { - // console.log('error', error); - // fs.unlinkSync(tempAudioPath); - // if (error) reject(error); - // }) - // .on('end', async function () { - // fs.unlinkSync(tempAudioPath); - // resolve(outputAudio); - // }) - // .run(); - // }); - // } - public async processAudio(audio: string, number: string) { this.logger.verbose('Processing audio'); let tempAudioPath: string; @@ -2506,50 +2420,8 @@ export class BaileysStartupService extends ChannelStartupService { ); } - public async buttonMessage(data: SendButtonDto) { - this.logger.verbose('Sending button message'); - const embeddedMedia: any = {}; - let mediatype = 'TEXT'; - - if (data.buttonMessage?.mediaMessage) { - mediatype = data.buttonMessage.mediaMessage?.mediatype.toUpperCase() ?? 'TEXT'; - embeddedMedia.mediaKey = mediatype.toLowerCase() + 'Message'; - const generate = await this.prepareMediaMessage(data.buttonMessage.mediaMessage); - embeddedMedia.message = generate.message[embeddedMedia.mediaKey]; - embeddedMedia.contentText = `*${data.buttonMessage.title}*\n\n${data.buttonMessage.description}`; - } - - const btnItems = { - text: data.buttonMessage.buttons.map((btn) => btn.buttonText), - ids: data.buttonMessage.buttons.map((btn) => btn.buttonId), - }; - - if (!arrayUnique(btnItems.text) || !arrayUnique(btnItems.ids)) { - throw new BadRequestException('Button texts cannot be repeated', 'Button IDs cannot be repeated.'); - } - - return await this.sendMessageWithTyping( - data.number, - { - buttonsMessage: { - text: !embeddedMedia?.mediaKey ? data.buttonMessage.title : undefined, - contentText: embeddedMedia?.contentText ?? data.buttonMessage.description, - footerText: data.buttonMessage?.footerText, - buttons: data.buttonMessage.buttons.map((button) => { - return { - buttonText: { - displayText: button.buttonText, - }, - buttonId: button.buttonId, - type: 1, - }; - }), - headerType: proto.Message.ButtonsMessage.HeaderType[mediatype], - [embeddedMedia?.mediaKey]: embeddedMedia?.message, - }, - }, - data?.options, - ); + public async buttonMessage() { + throw new BadRequestException('Method not available on WhatsApp Baileys'); } public async locationMessage(data: SendLocationDto) { diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index 3a7a2d15a..b4aa646cc 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.7.3 + version: 1.7.4 contact: name: DavidsonGomes email: contato@agenciadgcode.com