Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

javascript - how to send locally stored media files using twilio over whatsapp .. node js express

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();
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.5k users

...