Hello friends, I have this code to send audio recordings to S3, save the message in the database, and then send it to WhatsApp. However, I can't send audio files with WWebJS.
in frontend:
navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
this.mediaRecorder = new MediaRecorder(stream);
this.mediaRecorder.start();
this.isRecording = true;
this.audioChunks = [];
this.mediaRecorder.addEventListener("dataavailable", (event) => {
this.audioChunks.push(event.data);
});
this.mediaRecorder.addEventListener("stop", async () => {
const audioBlob = new Blob(this.audioChunks, {
type: "audio/ogg; codecs=opus",
});
const formData = new FormData();
formData.append("file", audioBlob);
formData.append("id", this.Chats[0].chatId);
formData.append("user", this.token.name);
formData.append("number", this.Chats[0].phoneNumber);
formData.append("chatId", this.id);
formData.append("mediaType", "audio/ogg; codecs=opus");
let response = await api.post("/api/v1/whatsapp/messages", formData, {
headers: {
"Content-Type": "multipart/form-data",
Authorization: "Bearer " + this.token.token,
},
});
this.isRecording = false;
await this.getMessages();
});
});
},```
