I’m trying to send various file types (images, videos, documents) using Twilio’s WhatsApp integration. While my proxy works perfectly for images, it fails for videos and documents, returning a format mismatch error in Twilio logs.
I’m trying to send a file along with my integration with Twilio for WhatsApp. I created a template that receives a URL which is a proxy, for example, https://myurl.com/proxy-file?file={{6}}. The proxy then returns the file to be sent via WhatsApp. It works very well with images, but it doesn’t work when it’s videos or documents, despite Twilio stating in the template creation that it is supported.
enter image description here
Here is my proxy implementation:
app.get('/proxy-file', async (request, reply) => {
const { file: fileUrl }: any = request.query
if (!fileUrl) {
reply.status(400).send('File URL is required')
return
}
try {
const response = await axios.get(fileUrl, {
responseType: 'arraybuffer',
})
let contentType = 'application/octet-stream'
if (fileUrl.endsWith('.pdf')) {
contentType = 'application/pdf'
} else if (fileUrl.endsWith('.doc')) {
contentType = 'application/msword'
} else if (fileUrl.endsWith('.docx')) {
contentType =
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
} else if (fileUrl.endsWith('.mp4')) {
contentType = 'video/mp4'
}
reply.header('Content-Type', contentType).send(response.data)
} catch (error) {
reply.status(500).send('Erro ao obter o arquivo')
}
})
But when I check the Twilio logs, it gives me this error, even when I send a PDF, for example.
Twilio Error: [This message send failed because it violates Channel provider's policy. Please see Channel specific error message for more information.] - Whatsapp Error: [msg=header: Format mismatch, expected IMAGE, received VIDEO, code=132012]
Rafael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.