node.js - Twilio 函数 : Sending WhatsApp message when incoming call is received

标签 node.js twilio whatsapp twilio-functions

我想使用 Twilio functions 在接到电话时运行我的操作。

简单的任务: 当我接到 twilio 号码上的电话时,我想转接电话并向 Whatsapp 号码发送消息以通知来电。

Twilio 网站上有一个类似的例子: Improve this question

但我无法让它与 WhatsApp 一起使用。 它仅适用于短信,但是当我用 to 数字替换 fromwhatsapp:+01234567890 参数时,我没有收到任何消息。

最佳答案

我发布了一种方法,用我的 Twilio WhatsApp 沙箱进行了测试,它有效。


/**
 *  This Function will forward a call to another phone number.
 *  It will send a WhatsApp message before doing that. 
 */

exports.handler = function (context, event, callback) {

    let fromNumber = event.From; // number which called our Twilio number  
    let recipientNumber = '+10000000001'; // number where the call will be forwarded

    let client = context.getTwilioClient();

    client.messages
        .create({
            from: 'whatsapp:+10000000002', // Twilio's WhatsApp sandbox number
            body: `Call from ${fromNumber}, forwarded to ${recipientNumber}.`,
            to: 'whatsapp:+10000000003' // WhatsApp number registered with sandbox
        })
        .then(function (message) {
            console.log(message.sid);
            forwardCall();
        });

    function forwardCall() {
        // generate the TwiML to tell Twilio how to forward this call
        let twiml = new Twilio.twiml.VoiceResponse();
        let dialParams = {};
        twiml.dial(dialParams, recipientNumber);
        // return the TwiML
        callback(null, twiml);
    }

};

关于node.js - Twilio 函数 : Sending WhatsApp message when incoming call is received,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56100810/

相关文章:

javascript - req.getValidationErrors() 不是一个函数

node.js - 一个请求中的多个查询

ios - Twilio iOS SDK 在去电时失败并显示 "400 Bad request"

php - 将 Twilio 与 Symfony2 集成

twilio - 如何通过 Twilio API 查看我的 Twilio 帐户电话号码列表?

javascript - nodejs 中的 RTMP 实现是可能的吗?

javascript - 迁移到 meteor / react

c# - 在 WinForms C# 中使用 WhatsAPINet 发送 WhatsApp 的密码错误

javascript - 如何在 Cordova 的 InAppBrowser 中优雅地中断加载某个 URL 并在系统浏览器中打开它?

Android WhatsApp 图片分享