mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -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
|
||||
/test/
|
||||
/src/env.yml
|
||||
|
||||
/temp
|
||||
|
@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
|
||||
import { load } from 'js-yaml';
|
||||
import { join } from 'path';
|
||||
import { SRC_DIR } from './path.config';
|
||||
import { isBooleanString } from 'class-validator';
|
||||
|
||||
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number };
|
||||
|
||||
@ -135,7 +136,7 @@ export class ConfigService {
|
||||
this.env.PRODUCTION = process.env?.NODE_ENV === 'PROD';
|
||||
if (process.env?.DOCKER_ENV === 'true') {
|
||||
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[],
|
||||
COLOR: process.env?.LOG_COLOR === 'true',
|
||||
},
|
||||
DEL_INSTANCE:
|
||||
typeof process.env?.DEL_INSTANCE === 'boolean'
|
||||
? process.env.DEL_INSTANCE === 'true'
|
||||
: Number.parseInt(process.env.DEL_INSTANCE),
|
||||
DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE)
|
||||
? process.env.DEL_INSTANCE === 'true'
|
||||
: Number.parseInt(process.env.DEL_INSTANCE),
|
||||
WEBHOOK: {
|
||||
GLOBAL: {
|
||||
URL: process.env?.WEBHOOK_GLOBAL_URL,
|
||||
|
@ -4,7 +4,7 @@ import { Logger } from '../config/logger.config';
|
||||
|
||||
const logger = new Logger('Db Connection');
|
||||
|
||||
export const db = configService.get<Database>('DATABASE');
|
||||
const db = configService.get<Database>('DATABASE');
|
||||
export const dbserver = db.ENABLED
|
||||
? mongoose.createConnection(db.CONNECTION.URI, {
|
||||
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) {
|
||||
try {
|
||||
const json = JSON.stringify(data, BufferJSON.replacer);
|
||||
|
@ -118,7 +118,7 @@ export class InstanceController {
|
||||
public async connectToWhatsapp({ instanceName }: InstanceDto) {
|
||||
try {
|
||||
const instance = this.waMonitor.waInstances[instanceName];
|
||||
const state = instance?.connectionStatus?.state ?? null;
|
||||
const state = instance?.connectionStatus?.state;
|
||||
|
||||
switch (state) {
|
||||
case 'close':
|
||||
@ -131,7 +131,7 @@ export class InstanceController {
|
||||
return await this.connectionState({ instanceName });
|
||||
}
|
||||
} 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 { join } from 'path';
|
||||
import { INSTANCE_DIR } from '../../config/path.config';
|
||||
import { db, dbserver } from '../../db/db.connect';
|
||||
import { dbserver } from '../../db/db.connect';
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
@ -10,9 +10,20 @@ import {
|
||||
} from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { waMonitor } from '../whatsapp.module';
|
||||
import { Database, Redis, configService } from '../../config/env.config';
|
||||
import { RedisCache } from '../../db/redis.client';
|
||||
|
||||
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) {
|
||||
const collection = dbserver
|
||||
|
@ -1146,8 +1146,8 @@ export class WAStartupService {
|
||||
let outputAudio: string;
|
||||
|
||||
if (isURL(audio)) {
|
||||
outputAudio = `${join(process.cwd(), 'temp', 'audio.opus')}`;
|
||||
tempAudioPath = `${join(process.cwd(), 'temp', 'audio.mp3')}`;
|
||||
outputAudio = `${join(process.cwd(), 'temp', 'audio.mp4')}`;
|
||||
tempAudioPath = `${join(process.cwd(), 'temp', 'audioTemp.mp3')}`;
|
||||
|
||||
const response = await axios.get(audio, { responseType: 'arraybuffer' });
|
||||
fs.writeFileSync(tempAudioPath, response.data);
|
||||
@ -1161,7 +1161,8 @@ export class WAStartupService {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
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) => {
|
||||
fs.unlinkSync(tempAudioPath);
|
||||
if (error) reject(error);
|
||||
@ -1179,11 +1180,9 @@ export class WAStartupService {
|
||||
data.number,
|
||||
{
|
||||
audio: Buffer.from(audio, 'base64'),
|
||||
// audio: isURL(data.audioMessage.audio)
|
||||
// ? { url: data.audioMessage.audio }
|
||||
// : Buffer.from(data.audioMessage.audio, 'base64'),
|
||||
ptt: true,
|
||||
mimetype: 'audio/ogg; codecs=opus',
|
||||
// mimetype: 'audio/ogg; codecs=opus',
|
||||
mimetype: 'audio/mp4',
|
||||
},
|
||||
{ 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