1
votes

Tried the twilio whatsapp api with sandbox(https://www.twilio.com/docs/sms/whatsapp/api#twilio-sandbox-for-whatsapp) to send message and it was successful. But,when tried to send the image file,it showed error in the dashboard as ' 12400 An internal error has occurred that prevented Twilio from processing your response.' The same format in which message was sent was used except the parameter was changed to 'MediaUrl'.

1) Is there anything else to be taken care while image files are being sent? 2) Is it possible to send attachment like excel/pdf using the whatsapp api of twilio?

5

5 Answers

2
votes

It isn't supported yet.

Twilio API for WhatsApp

https://www.twilio.com/docs/sms/whatsapp/api#sending-a-freeform-whatsapp-message-using-the-api

"Support for sending media in outbound messages is coming soon."

0
votes

Well only media sending from twilio whatsapp is not supported but with text you can send it, If you are willing to send only an image then add space in your message body and it will work.

See my code in PHP

$get_response = $client->messages->create(
    $phone, array(
        'from' => $sender_id, //Whatsapp:+1xxxxxxxxxx
        'body' => " ", //Add blank space here
        'mediaUrl' => $mediaUrl, //http://example.com/mms_file/image.jpg
    )
);

Here I add blank space in body and I have start receiving images.

0
votes

Looks like now it's possible.

To send a freeform WhatsApp message with media attachment, include MediaUrl parameter in your message. Supported media include images (JPG, JPEG, PNG), audio files and PDF. One media attachment is supported per message, with a size limit of 5MB.

https://www.twilio.com/docs/sms/whatsapp/api#sending-a-freeform-whatsapp-message-with-media-attachment

Although inbound is still coming soon:

Support for Inbound media and location is coming soon.

0
votes
const string accountSid = "ACxxxxxxxxx....";
const string authToken = "b4xxxxx......";
Uri img = new Uri("http://youserver.com/images/filename.jpeg");
List<Uri> listImg = new List<Uri>();
listImg.Add(img);

TwilioClient.Init(accountSid, authToken);

var message = MessageResource.Create(
                body: "Hello word!",
                from: new Twilio.Types.PhoneNumber("whatsapp:+1xxxxxxxx"),
                to: new Twilio.Types.PhoneNumber("whatsapp:+1xxxxxxxxx"),
                mediaUrl: listImg);            
0
votes

Although the WhatsApp API integration in Twilio is still in beta and they're working with the WhatsApp Team for the best integration, I have successfully sent an MP3 audio message through the sandbox environment.

The logic is:

From the WhatsApp app I send a message to the Twilio sandbox number.
- Twilio receive the message and forward (POST) it through the webhook to a my Node.js app endpoint hosted in Heroku.
- The Heroku Node app receive the message and do some logic.
- After the logic is done I need to reply with a text message followed by an audio message, below the snippet that I've used:

const client = require('twilio')(accountSid, authToken); 
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const twiml = new MessagingResponse();

//Text Message 
var msg = twiml.message("Text Message");//Text Message
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());

//Audio Message
client.messages
   .create({
       to: req.body.From,//req is the request arrived from the Twilio forward webhook
       from: req.body.To,
       body: "",
       mediaUrl: "http://www.example.com/audio/test.mp3",
   })
   .then((message) => console.log(message.sid));

When the audio message arrives into the WhatsApp App you can listen it directly without browse the link where the audio is hosted.

Keep in mind that WhatsApp could block messages but in this case you should see the error logs in the Twilio Dashboard.