Skip to content

Commit d6e19b9

Browse files
committed
adjusts in v1.7.3
1 parent 5e0e405 commit d6e19b9

File tree

5 files changed

+111
-42
lines changed

5 files changed

+111
-42
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.7.3 (develop)
2+
3+
### Fixed
4+
* Fix audio encoding
5+
* Recovering messages lost
6+
* Adjusts in proxy
7+
18
# 1.7.2 (2024-04-12 17:31)
29

310
### Feature

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:20.7.0-alpine AS builder
22

3-
LABEL version="1.7.2" description="Api to control whatsapp features through http requests."
3+
LABEL version="1.7.3" description="Api to control whatsapp features through http requests."
44
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
55
LABEL contact="contato@agenciadgcode.com"
66

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "evolution-api",
3-
"version": "1.7.2",
3+
"version": "1.7.3",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/src/main.js",
66
"scripts": {

src/api/services/whatsapp/whatsapp.baileys.service.ts

Lines changed: 101 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ import makeWASocket, {
3939
import { Label } from '@whiskeysockets/baileys/lib/Types/Label';
4040
import { LabelAssociation } from '@whiskeysockets/baileys/lib/Types/LabelAssociation';
4141
import axios from 'axios';
42+
import { exec } from 'child_process';
4243
import { arrayUnique, isBase64, isURL } from 'class-validator';
4344
import EventEmitter2 from 'eventemitter2';
44-
import ffmpeg from 'fluent-ffmpeg';
45+
// import ffmpeg from 'fluent-ffmpeg';
4546
import fs, { existsSync, readFileSync } from 'fs';
4647
import { parsePhoneNumber } from 'libphonenumber-js';
4748
import Long from 'long';
@@ -485,11 +486,11 @@ export class BaileysStartupService extends WAStartupService {
485486
let options;
486487

487488
if (this.localProxy.enabled) {
488-
this.logger.info('Proxy enabled: ' + this.localProxy.proxy.host);
489+
this.logger.info('Proxy enabled: ' + this.localProxy.proxy?.host);
489490

490491
if (this.localProxy?.proxy?.host?.includes('proxyscrape')) {
491492
try {
492-
const response = await axios.get(this.localProxy.proxy.host);
493+
const response = await axios.get(this.localProxy.proxy?.host);
493494
const text = response.data;
494495
const proxyUrls = text.split('\r\n');
495496
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
@@ -655,11 +656,11 @@ export class BaileysStartupService extends WAStartupService {
655656
let options;
656657

657658
if (this.localProxy.enabled) {
658-
this.logger.info('Proxy enabled: ' + this.localProxy.proxy.host);
659+
this.logger.info('Proxy enabled: ' + this.localProxy.proxy?.host);
659660

660661
if (this.localProxy?.proxy?.host?.includes('proxyscrape')) {
661662
try {
662-
const response = await axios.get(this.localProxy.proxy.host);
663+
const response = await axios.get(this.localProxy.proxy?.host);
663664
const text = response.data;
664665
const proxyUrls = text.split('\r\n');
665666
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
@@ -1043,6 +1044,12 @@ export class BaileysStartupService extends WAStartupService {
10431044
}
10441045
}
10451046

1047+
if (received.messageStubParameters && received.messageStubParameters[0] === 'Message absent from node') {
1048+
this.logger.info('Recovering message lost');
1049+
await this.client.sendMessageAck(JSON.parse(received.messageStubParameters[1], BufferJSON.reviver));
1050+
continue;
1051+
}
1052+
10461053
if (
10471054
(type !== 'notify' && type !== 'append') ||
10481055
received.message?.protocolMessage ||
@@ -2093,7 +2100,7 @@ export class BaileysStartupService extends WAStartupService {
20932100
content: {
20942101
audio: Buffer.from(audio, 'base64'),
20952102
ptt: true,
2096-
mimetype: 'audio/mp4',
2103+
mimetype: 'audio/ogg; codecs=opus',
20972104
},
20982105
option: {
20992106
statusJidList: status.statusJidList,
@@ -2297,6 +2304,82 @@ export class BaileysStartupService extends WAStartupService {
22972304
return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot);
22982305
}
22992306

2307+
// public async processAudio(audio: string, number: string) {
2308+
// this.logger.verbose('Processing audio');
2309+
// let tempAudioPath: string;
2310+
// let outputAudio: string;
2311+
2312+
// number = number.replace(/\D/g, '');
2313+
// const hash = `${number}-${new Date().getTime()}`;
2314+
// this.logger.verbose('Hash to audio name: ' + hash);
2315+
2316+
// if (isURL(audio)) {
2317+
// this.logger.verbose('Audio is url');
2318+
2319+
// outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`;
2320+
// tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
2321+
2322+
// this.logger.verbose('Output audio path: ' + outputAudio);
2323+
// this.logger.verbose('Temp audio path: ' + tempAudioPath);
2324+
2325+
// const timestamp = new Date().getTime();
2326+
// const url = `${audio}?timestamp=${timestamp}`;
2327+
2328+
// this.logger.verbose('Including timestamp in url: ' + url);
2329+
2330+
// let config: any = {
2331+
// responseType: 'arraybuffer',
2332+
// };
2333+
2334+
// if (this.localProxy.enabled) {
2335+
// config = {
2336+
// ...config,
2337+
// httpsAgent: makeProxyAgent(this.localProxy.proxy),
2338+
// };
2339+
// }
2340+
2341+
// const response = await axios.get(url, config);
2342+
// this.logger.verbose('Getting audio from url');
2343+
2344+
// fs.writeFileSync(tempAudioPath, response.data);
2345+
// } else {
2346+
// this.logger.verbose('Audio is base64');
2347+
2348+
// outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`;
2349+
// tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
2350+
2351+
// this.logger.verbose('Output audio path: ' + outputAudio);
2352+
// this.logger.verbose('Temp audio path: ' + tempAudioPath);
2353+
2354+
// const audioBuffer = Buffer.from(audio, 'base64');
2355+
// fs.writeFileSync(tempAudioPath, audioBuffer);
2356+
// this.logger.verbose('Temp audio created');
2357+
// }
2358+
2359+
// this.logger.verbose('Converting audio to mp4');
2360+
// return new Promise((resolve, reject) => {
2361+
// // This fix was suggested by @PurpShell
2362+
// ffmpeg.setFfmpegPath(ffmpegPath.path);
2363+
2364+
// ffmpeg()
2365+
// .input(tempAudioPath)
2366+
// .outputFormat('ogg')
2367+
// .noVideo()
2368+
// .audioCodec('libopus')
2369+
// .save(outputAudio)
2370+
// .on('error', function (error) {
2371+
// console.log('error', error);
2372+
// fs.unlinkSync(tempAudioPath);
2373+
// if (error) reject(error);
2374+
// })
2375+
// .on('end', async function () {
2376+
// fs.unlinkSync(tempAudioPath);
2377+
// resolve(outputAudio);
2378+
// })
2379+
// .run();
2380+
// });
2381+
// }
2382+
23002383
public async processAudio(audio: string, number: string) {
23012384
this.logger.verbose('Processing audio');
23022385
let tempAudioPath: string;
@@ -2309,7 +2392,7 @@ export class BaileysStartupService extends WAStartupService {
23092392
if (isURL(audio)) {
23102393
this.logger.verbose('Audio is url');
23112394

2312-
outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`;
2395+
outputAudio = `${join(this.storePath, 'temp', `${hash}.mp4`)}`;
23132396
tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
23142397

23152398
this.logger.verbose('Output audio path: ' + outputAudio);
@@ -2320,25 +2403,14 @@ export class BaileysStartupService extends WAStartupService {
23202403

23212404
this.logger.verbose('Including timestamp in url: ' + url);
23222405

2323-
let config: any = {
2324-
responseType: 'arraybuffer',
2325-
};
2326-
2327-
if (this.localProxy.enabled) {
2328-
config = {
2329-
...config,
2330-
httpsAgent: makeProxyAgent(this.localProxy.proxy),
2331-
};
2332-
}
2333-
2334-
const response = await axios.get(url, config);
2406+
const response = await axios.get(url, { responseType: 'arraybuffer' });
23352407
this.logger.verbose('Getting audio from url');
23362408

23372409
fs.writeFileSync(tempAudioPath, response.data);
23382410
} else {
23392411
this.logger.verbose('Audio is base64');
23402412

2341-
outputAudio = `${join(this.storePath, 'temp', `${hash}.ogg`)}`;
2413+
outputAudio = `${join(this.storePath, 'temp', `${hash}.mp4`)}`;
23422414
tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
23432415

23442416
this.logger.verbose('Output audio path: ' + outputAudio);
@@ -2351,25 +2423,15 @@ export class BaileysStartupService extends WAStartupService {
23512423

23522424
this.logger.verbose('Converting audio to mp4');
23532425
return new Promise((resolve, reject) => {
2354-
// This fix was suggested by @PurpShell
2355-
ffmpeg.setFfmpegPath(ffmpegPath.path);
2356-
2357-
ffmpeg()
2358-
.input(tempAudioPath)
2359-
.outputFormat('ogg')
2360-
.noVideo()
2361-
.audioCodec('libopus')
2362-
.save(outputAudio)
2363-
.on('error', function (error) {
2364-
console.log('error', error);
2365-
fs.unlinkSync(tempAudioPath);
2366-
if (error) reject(error);
2367-
})
2368-
.on('end', async function () {
2369-
fs.unlinkSync(tempAudioPath);
2370-
resolve(outputAudio);
2371-
})
2372-
.run();
2426+
exec(`${ffmpegPath.path} -i ${tempAudioPath} -vn -ab 128k -ar 44100 -f ipod ${outputAudio} -y`, (error) => {
2427+
fs.unlinkSync(tempAudioPath);
2428+
this.logger.verbose('Temp audio deleted');
2429+
2430+
if (error) reject(error);
2431+
2432+
this.logger.verbose('Audio converted to mp4');
2433+
resolve(outputAudio);
2434+
});
23732435
});
23742436
}
23752437

src/docs/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ info:
2525
</font>
2626
2727
[![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)
28-
version: 1.7.2
28+
version: 1.7.3
2929
contact:
3030
name: DavidsonGomes
3131
email: contato@agenciadgcode.com

0 commit comments

Comments
 (0)