如何使用 twilio 通过 whatsapp 发送本地存储的媒体文件 .. node js express

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

Midlaj,你好!这里是 Twilio 开发人员传道者。

您不能使用本地路径,因为媒体 url 必须可供 Twilio 的服务器公开访问(即它必须具有 URL),以便可以检索资产并将其添加到信息。如果本地路径被接受,它将指向随机 Twilio 服务器上的“/Users/Name/file.gif”。

您可以使用Twilio Assets发送本地文件。您也可以使用 Ngrok.com 将您的本地网络服务器公开到互联网,使用 ngrok 托管文件并在外部共享本地文件。

如果这有帮助,请告诉我!