mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 04:02:54 -06:00
conversion of audios for sending recorded audio, now it is possible to send mp3 audios and not just ogg
This commit is contained in:
parent
631dd01c92
commit
b8fa43296d
2
.gitignore
vendored
2
.gitignore
vendored
@ -33,3 +33,5 @@ lerna-debug.log*
|
|||||||
!/instances/.gitkeep
|
!/instances/.gitkeep
|
||||||
/test/
|
/test/
|
||||||
/src/env.yml
|
/src/env.yml
|
||||||
|
|
||||||
|
/temp
|
||||||
|
@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
|
|||||||
import { load } from 'js-yaml';
|
import { load } from 'js-yaml';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { SRC_DIR } from './path.config';
|
import { SRC_DIR } from './path.config';
|
||||||
|
import { isBooleanString } from 'class-validator';
|
||||||
|
|
||||||
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number };
|
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number };
|
||||||
|
|
||||||
@ -135,7 +136,7 @@ export class ConfigService {
|
|||||||
this.env.PRODUCTION = process.env?.NODE_ENV === 'PROD';
|
this.env.PRODUCTION = process.env?.NODE_ENV === 'PROD';
|
||||||
if (process.env?.DOCKER_ENV === 'true') {
|
if (process.env?.DOCKER_ENV === 'true') {
|
||||||
this.env.SERVER.TYPE = 'http';
|
this.env.SERVER.TYPE = 'http';
|
||||||
this.env.SERVER.PORT = Number.parseInt(process.env?.SERVER_PORT ?? '8080');
|
this.env.SERVER.PORT = 8080;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,10 +191,9 @@ export class ConfigService {
|
|||||||
LEVEL: process.env?.LOG_LEVEL.split(',') as LogLevel[],
|
LEVEL: process.env?.LOG_LEVEL.split(',') as LogLevel[],
|
||||||
COLOR: process.env?.LOG_COLOR === 'true',
|
COLOR: process.env?.LOG_COLOR === 'true',
|
||||||
},
|
},
|
||||||
DEL_INSTANCE:
|
DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE)
|
||||||
typeof process.env?.DEL_INSTANCE === 'boolean'
|
? process.env.DEL_INSTANCE === 'true'
|
||||||
? process.env.DEL_INSTANCE === 'true'
|
: Number.parseInt(process.env.DEL_INSTANCE),
|
||||||
: Number.parseInt(process.env.DEL_INSTANCE),
|
|
||||||
WEBHOOK: {
|
WEBHOOK: {
|
||||||
GLOBAL: {
|
GLOBAL: {
|
||||||
URL: process.env?.WEBHOOK_GLOBAL_URL,
|
URL: process.env?.WEBHOOK_GLOBAL_URL,
|
||||||
|
@ -4,7 +4,7 @@ import { Logger } from '../config/logger.config';
|
|||||||
|
|
||||||
const logger = new Logger('Db Connection');
|
const logger = new Logger('Db Connection');
|
||||||
|
|
||||||
export const db = configService.get<Database>('DATABASE');
|
const db = configService.get<Database>('DATABASE');
|
||||||
export const dbserver = db.ENABLED
|
export const dbserver = db.ENABLED
|
||||||
? mongoose.createConnection(db.CONNECTION.URI, {
|
? mongoose.createConnection(db.CONNECTION.URI, {
|
||||||
dbName: db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api',
|
dbName: db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api',
|
||||||
|
@ -25,6 +25,13 @@ export class RedisCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async keyExists(key?: string) {
|
||||||
|
if (key) {
|
||||||
|
return !!(await this.instanceKeys()).find((i) => i === key);
|
||||||
|
}
|
||||||
|
return !!(await this.instanceKeys()).find((i) => i === this.instanceName);
|
||||||
|
}
|
||||||
|
|
||||||
public async writeData(field: string, data: any) {
|
public async writeData(field: string, data: any) {
|
||||||
try {
|
try {
|
||||||
const json = JSON.stringify(data, BufferJSON.replacer);
|
const json = JSON.stringify(data, BufferJSON.replacer);
|
||||||
|
@ -118,7 +118,7 @@ export class InstanceController {
|
|||||||
public async connectToWhatsapp({ instanceName }: InstanceDto) {
|
public async connectToWhatsapp({ instanceName }: InstanceDto) {
|
||||||
try {
|
try {
|
||||||
const instance = this.waMonitor.waInstances[instanceName];
|
const instance = this.waMonitor.waInstances[instanceName];
|
||||||
const state = instance?.connectionStatus?.state ?? null;
|
const state = instance?.connectionStatus?.state;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 'close':
|
case 'close':
|
||||||
@ -131,7 +131,7 @@ export class InstanceController {
|
|||||||
return await this.connectionState({ instanceName });
|
return await this.connectionState({ instanceName });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.log(error);
|
this.logger.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express';
|
|||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { INSTANCE_DIR } from '../../config/path.config';
|
import { INSTANCE_DIR } from '../../config/path.config';
|
||||||
import { db, dbserver } from '../../db/db.connect';
|
import { dbserver } from '../../db/db.connect';
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
@ -10,9 +10,20 @@ import {
|
|||||||
} from '../../exceptions';
|
} from '../../exceptions';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { waMonitor } from '../whatsapp.module';
|
import { waMonitor } from '../whatsapp.module';
|
||||||
|
import { Database, Redis, configService } from '../../config/env.config';
|
||||||
|
import { RedisCache } from '../../db/redis.client';
|
||||||
|
|
||||||
async function getInstance(instanceName: string) {
|
async function getInstance(instanceName: string) {
|
||||||
const exists = waMonitor.waInstances[instanceName];
|
const db = configService.get<Database>('DATABASE');
|
||||||
|
const redisConf = configService.get<Redis>('REDIS');
|
||||||
|
|
||||||
|
const exists = !!waMonitor.waInstances[instanceName];
|
||||||
|
|
||||||
|
if (redisConf.ENABLED) {
|
||||||
|
const cache = new RedisCache(redisConf, instanceName);
|
||||||
|
const keyExists = await cache.keyExists();
|
||||||
|
return exists || keyExists;
|
||||||
|
}
|
||||||
|
|
||||||
if (db.ENABLED) {
|
if (db.ENABLED) {
|
||||||
const collection = dbserver
|
const collection = dbserver
|
||||||
|
@ -1146,8 +1146,8 @@ export class WAStartupService {
|
|||||||
let outputAudio: string;
|
let outputAudio: string;
|
||||||
|
|
||||||
if (isURL(audio)) {
|
if (isURL(audio)) {
|
||||||
outputAudio = `${join(process.cwd(), 'temp', 'audio.opus')}`;
|
outputAudio = `${join(process.cwd(), 'temp', 'audio.mp4')}`;
|
||||||
tempAudioPath = `${join(process.cwd(), 'temp', 'audio.mp3')}`;
|
tempAudioPath = `${join(process.cwd(), 'temp', 'audioTemp.mp3')}`;
|
||||||
|
|
||||||
const response = await axios.get(audio, { responseType: 'arraybuffer' });
|
const response = await axios.get(audio, { responseType: 'arraybuffer' });
|
||||||
fs.writeFileSync(tempAudioPath, response.data);
|
fs.writeFileSync(tempAudioPath, response.data);
|
||||||
@ -1161,7 +1161,8 @@ export class WAStartupService {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(
|
exec(
|
||||||
`${ffmpegPath.path} -i ${tempAudioPath} -c:a libopus ${outputAudio} -y`,
|
// `${ffmpegPath.path} -i ${tempAudioPath} -c:a libopus ${outputAudio} -y`,
|
||||||
|
`${ffmpegPath.path} -i ${tempAudioPath} -vn -ab 128k -ar 44100 -f ipod ${outputAudio} -y`,
|
||||||
(error, _stdout, _stderr) => {
|
(error, _stdout, _stderr) => {
|
||||||
fs.unlinkSync(tempAudioPath);
|
fs.unlinkSync(tempAudioPath);
|
||||||
if (error) reject(error);
|
if (error) reject(error);
|
||||||
@ -1179,11 +1180,9 @@ export class WAStartupService {
|
|||||||
data.number,
|
data.number,
|
||||||
{
|
{
|
||||||
audio: Buffer.from(audio, 'base64'),
|
audio: Buffer.from(audio, 'base64'),
|
||||||
// audio: isURL(data.audioMessage.audio)
|
|
||||||
// ? { url: data.audioMessage.audio }
|
|
||||||
// : Buffer.from(data.audioMessage.audio, 'base64'),
|
|
||||||
ptt: true,
|
ptt: true,
|
||||||
mimetype: 'audio/ogg; codecs=opus',
|
// mimetype: 'audio/ogg; codecs=opus',
|
||||||
|
mimetype: 'audio/mp4',
|
||||||
},
|
},
|
||||||
{ presence: 'recording', delay: data?.options?.delay },
|
{ presence: 'recording', delay: data?.options?.delay },
|
||||||
);
|
);
|
||||||
|
BIN
temp/audio.opus
BIN
temp/audio.opus
Binary file not shown.
Loading…
Reference in New Issue
Block a user