Skip to content

Commit 83567d6

Browse files
author
nestordavalos
committed
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.
1 parent d7ddb99 commit 83567d6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/api/controllers/sendMessage.controller.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ export class SendMessageController {
4747
}
4848

4949
public async sendWhatsAppAudio({ instanceName }: InstanceDto, data: SendAudioDto, file?: any) {
50-
if (file || isURL(data.audio) || isBase64(data.audio)) {
51-
return await this.waMonitor.waInstances[instanceName].audioWhatsapp(data, file);
50+
if (file?.buffer || isURL(data.audio) || isBase64(data.audio)) {
51+
// Si file existe y tiene buffer, o si es una URL o Base64, continúa
52+
return await this.waMonitor.waInstances[instanceName].audioWhatsapp(data, file);
53+
} else {
54+
console.error('El archivo no tiene buffer o el audio no es una URL o Base64 válida');
55+
throw new BadRequestException('Owned media must be a url, base64, or valid file with buffer');
5256
}
53-
throw new BadRequestException('Owned media must be a url or base64');
54-
}
57+
}
5558

5659
public async sendButtons({ instanceName }: InstanceDto, data: SendButtonDto) {
5760
return await this.waMonitor.waInstances[instanceName].buttonMessage(data);

0 commit comments

Comments
 (0)