Reputation: 57
I need to send the generated PDF as a whatsapp message, but it shows an error when I try to read my file.
easyinvoice.createInvoice(data, function(result) {
//The response will contain a base64 encoded PDF file
fs.writeFileSync("invoice.pdf", result.pdf, 'base64');
var s = result.pdf;
client.messages
.create({
mediaUrl: s,
body: 'invoice',
from: 'whatsapp:+somenumber',
to: 'whatsapp:+somenumber'
})
.then(message => console.log(message.sid))
.done();
});
Upvotes: 1
Views: 2585
Reputation: 3300
Midlaj, hi! Twilio developer evangelist here.
You cannot use a local path because media url has to be publicly accessible to Twilio's servers (ie it has to have a URL) so that the asset can be retrieved and added to the message. If a local path were accepted, it would point to "/Users/Name/file.gif" on a random Twilio server.
You can use Twilio Assets to send local files. You could alternatively also use Ngrok.com to expose your local webserver to the internet, hosting the files with ngrok and sharing the local files externally.
Let me know if this helps at all!
Upvotes: 5