Skip to content

Commit

Permalink
v 1.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Apr 28, 2024
1 parent 14c210c commit 95907b3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 135 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.7.4 (develop)
# 1.7.4 (2024-04-28 09:46)

### Fixed
* Adjusts in proxy on fetchAgent
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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="[email protected]"

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
134 changes: 3 additions & 131 deletions src/api/services/channels/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -97,7 +97,6 @@ import {
MediaMessage,
Options,
SendAudioDto,
SendButtonDto,
SendContactDto,
SendListDto,
SendLocationDto,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ info:
</font>
[![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: [email protected]
Expand Down

0 comments on commit 95907b3

Please sign in to comment.