sending ogg file to whatsapp using twilio

406 views Asked by At

I am building a chatbot on whatsapp using twilio. One step is to send an .ogg (or other audio format such as mpeg) file to whatsapp as a reply. However, it fails to receive the message on whatsapp. When I change the .ogg file to an image file (such as .png) it is successful. One twilio documents (https://www.twilio.com/docs/sms/accepted-mime-types), it says .ogg (or .mpeg) is accepted. So what is the problem?

to_num = request.values.get('From', '')
from_num = request.values.get('To', '')
message = client.messages.create(
                              from_= from_num,
                              body= "test", 
                              media_url= "https://the_file_link.ogg",
                              to= to_num
                          )

expecting to receive audio in whatsapp. When sending text and image, it is ok. When sending text and audio, it fails.

1

There are 1 answers

0
mayo On

I had the same error sending an ogg file! I went into twilio console to check the logs and I saw this error/warning:

63005 Channel did not accept given content. Please see Channel specific error message for more information

Didn't have luck trying with that error code. But then reading the documentation I saw this;

**WhatsApp outbound OGG is only supported when the ogg file uses the opus audio codec. These files may have the .ogg or the .opus extension.

Since I was using pydub, specifying the desired codec solved the issue;

from pydub import AudioSegment

def _convert_to_ogg(source_file, destination):
    segment = AudioSegment.from_mp3(source_file)
    segment.export(destination format="ogg", codec='libopus')