mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-23 17:08:44 -06:00
fix: Corregir manejo de archivo de audio en WhatsApp
This commit is contained in:
parent
83567d6466
commit
59af93251d
@ -483,7 +483,12 @@ export class EvolutionStartupService extends ChannelStartupService {
|
|||||||
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
||||||
const mediaData: SendAudioDto = { ...data };
|
const mediaData: SendAudioDto = { ...data };
|
||||||
|
|
||||||
if (file) mediaData.audio = file.buffer.toString('base64');
|
if (file?.buffer) {
|
||||||
|
mediaData.audio = file.buffer.toString('base64');
|
||||||
|
} else {
|
||||||
|
console.error("El archivo o buffer no está definido correctamente.");
|
||||||
|
throw new Error("File or buffer is undefined.");
|
||||||
|
}
|
||||||
|
|
||||||
const message = await this.processAudio(mediaData.audio, data.number);
|
const message = await this.processAudio(mediaData.audio, data.number);
|
||||||
|
|
||||||
|
@ -1081,7 +1081,13 @@ export class BusinessStartupService extends ChannelStartupService {
|
|||||||
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
||||||
const mediaData: SendAudioDto = { ...data };
|
const mediaData: SendAudioDto = { ...data };
|
||||||
|
|
||||||
if (file) mediaData.audio = file.buffer.toString('base64');
|
if (file?.buffer) {
|
||||||
|
// Asegurarse de que file y buffer existen antes de usarlos
|
||||||
|
mediaData.audio = file.buffer.toString('base64');
|
||||||
|
} else {
|
||||||
|
console.error('El archivo no tiene buffer o file es undefined');
|
||||||
|
throw new Error('File or buffer is undefined');
|
||||||
|
}
|
||||||
|
|
||||||
const message = await this.processAudio(mediaData.audio, data.number);
|
const message = await this.processAudio(mediaData.audio, data.number);
|
||||||
|
|
||||||
|
@ -2574,42 +2574,47 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
||||||
const mediaData: SendAudioDto = { ...data };
|
const mediaData: SendAudioDto = { ...data };
|
||||||
|
|
||||||
if (file) mediaData.audio = file.buffer.toString('base64');
|
if (file?.buffer) {
|
||||||
|
mediaData.audio = file.buffer.toString('base64');
|
||||||
|
} else if (!isURL(data.audio) && !isBase64(data.audio)) {
|
||||||
|
console.error('Invalid file or audio source');
|
||||||
|
throw new BadRequestException('File buffer, URL, or base64 audio is required');
|
||||||
|
}
|
||||||
|
|
||||||
if (!data?.encoding && data?.encoding !== false) {
|
if (!data?.encoding && data?.encoding !== false) {
|
||||||
data.encoding = true;
|
data.encoding = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data?.encoding) {
|
if (data?.encoding) {
|
||||||
const convert = await this.processAudio(mediaData.audio);
|
const convert = await this.processAudio(mediaData.audio);
|
||||||
|
|
||||||
if (Buffer.isBuffer(convert)) {
|
if (Buffer.isBuffer(convert)) {
|
||||||
const result = this.sendMessageWithTyping<AnyMessageContent>(
|
const result = this.sendMessageWithTyping<AnyMessageContent>(
|
||||||
data.number,
|
data.number,
|
||||||
{
|
{
|
||||||
audio: convert,
|
audio: convert,
|
||||||
ptt: true,
|
ptt: true,
|
||||||
mimetype: 'audio/ogg; codecs=opus',
|
mimetype: 'audio/ogg; codecs=opus',
|
||||||
},
|
},
|
||||||
{ presence: 'recording', delay: data?.delay },
|
{ presence: 'recording', delay: data?.delay },
|
||||||
isIntegration,
|
isIntegration,
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
throw new InternalServerErrorException('Failed to convert audio');
|
throw new InternalServerErrorException('Failed to convert audio');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.sendMessageWithTyping<AnyMessageContent>(
|
return await this.sendMessageWithTyping<AnyMessageContent>(
|
||||||
data.number,
|
data.number,
|
||||||
{
|
{
|
||||||
audio: isURL(data.audio) ? { url: data.audio } : Buffer.from(data.audio, 'base64'),
|
audio: isURL(data.audio) ? { url: data.audio } : Buffer.from(data.audio, 'base64'),
|
||||||
ptt: true,
|
ptt: true,
|
||||||
mimetype: 'audio/ogg; codecs=opus',
|
mimetype: 'audio/ogg; codecs=opus',
|
||||||
},
|
},
|
||||||
{ presence: 'recording', delay: data?.delay },
|
{ presence: 'recording', delay: data?.delay },
|
||||||
isIntegration,
|
isIntegration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user