How to use Twilio to send customized PDF’s from Google Drive/Sheets

Viewed 344

I am having problems trying to send customized PDFs from Google Drive to users on WhatsApp using Twilio’s API.

I am using node.js and the documents are created in Google Sheets and stored in Google Drive.

 client.messages
  .create({
     mediaUrl:['https://drive.google.com/uc?id=INSERT_FILE_ID&export=download'],
     from: 'whatsapp:+14155238886',
     body: `It's taco time!`,
     to: 'whatsapp:+15017122661'
   })
  .then(message => console.log(message.sid));

I thought it would be possible to send the PDF by passing the PDF’s Drive link through MediaURL as that is what is recommended on Twilio’s site for sending media (Images, .mp3’s and PDF’s) but when I try that it doesn’t work.

NB: it works when I try image URL’s etc.

I have tried sending the webContentLink of the PDF that also doesn’t work.

example: how the pdf should look when sent

I do not want to send the user a normal link for them to leave WhatsApp.

Any help with this or any other method to achieve this would be greatly appreciated.

1 Answers

Twilio will check the content-type of the file which you have been passing in the mediaUrl parameter. Twilio will reject if the content-type headers of your media attachment do not match the file extension (for example, content-type is image/jpg but the file extension is .png). It specified in the following links specifies:

  1. Twilio Troubleshooting

  2. Twilio supported-mime-types

Related