I am trying to send audio message with twillio conversations. According to the documentation I should send a contentType and a media of type string or Buffer. The Buffer constructor is missing in JS so I used the following method to create a buffer: Here is my send message request (I have tried sending different content types. And even audio in base64. Nothing worked.):
function toBuffer(ab: any) {
const buf = Buffer.alloc(ab.byteLength)
const view = new Uint8Array(ab)
for (let i = 0; i < buf.length; i += 1) {
buf[i] = view[i]
}
return buf
}
const arrayBuffer = await new FileReader().readAsArrayBuffer(new Blob([message.audio]))
chats[chat].conversation?.sendMessage({
contentType: 'audio/wav',
media: toBuffer(arrayBuffer)
}, {
messageId: uuidv4(),
...attributes
})
I request the audio URL with the function provided by twillio conversations:
message.media.getContentTemporaryUrl()
It returns a URL which doe not contain a valid audio file and cannot be played. Please help me to find the propper way of send a valid audo message and being able to play it. Thanks