简体   繁体   English

如何使用 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.我需要将生成的 PDF 作为 whatsapp 消息发送,但是当我尝试读取文件时它显示错误。

 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, hi.米德拉杰,你好。 Twilio developer evangelist here. Twilio 开发人员布道师在这里。

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.您不能使用本地路径,因为媒体 url 必须可供 Twilio 的服务器公开访问(即它必须具有 URL),以便可以检索资产并将其添加到消息中。 If a local path were accepted, it would point to "/Users/Name/file.gif" on a random Twilio server.如果接受本地路径,它将指向随机 Twilio 服务器上的“/Users/Name/file.gif”。

You can use Twilio Assets to send local files.您可以使用Twilio 资产发送本地文件。 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.您也可以使用 Ngrok.com 将本地 Web 服务器公开到 Internet,使用 ngrok 托管文件并在外部共享本地文件。

Let me know if this helps at all!让我知道这是否有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM