fix: Corrected audio file handling in WhatsApp

An error in the WhatsApp audio message handler has been fixed. The system now checks if the file has a valid buffer before sending it. Additionally, validation has been added to verify if the audio is a valid URL or Base64. If these conditions are not met, an error message is shown, and a BadRequestException is thrown.
This commit is contained in:
nestordavalos 2024-10-05 22:49:30 -04:00
parent d7ddb99fb0
commit 83567d6466

View File

@ -47,10 +47,13 @@ export class SendMessageController {
}
public async sendWhatsAppAudio({ instanceName }: InstanceDto, data: SendAudioDto, file?: any) {
if (file || isURL(data.audio) || isBase64(data.audio)) {
if (file?.buffer || isURL(data.audio) || isBase64(data.audio)) {
// Si file existe y tiene buffer, o si es una URL o Base64, continúa
return await this.waMonitor.waInstances[instanceName].audioWhatsapp(data, file);
} else {
console.error('El archivo no tiene buffer o el audio no es una URL o Base64 válida');
throw new BadRequestException('Owned media must be a url, base64, or valid file with buffer');
}
throw new BadRequestException('Owned media must be a url or base64');
}
public async sendButtons({ instanceName }: InstanceDto, data: SendButtonDto) {