如何使用twilio将两个匿名呼叫者连接在一起

时间:2014-11-05 17:20:57

标签: node.js twilio twilio-click-to-call

我目前正在使用node js twilio模块来实现我正在为客户端工作的项目中的功能。基本上服务器将使用twilio api发起呼叫呼叫某个人A将他连接到另一个人B.我是twilio的新手,所以我仍然是一个菜鸟,但这是我到目前为止编写的代码。我需要你们输入如何实现这一目标。欢呼声

var client = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);

exports.makeCall = function(callDetails, cb) {

  client.makeCall({
    to:'+16515556677', // Any number Twilio can call
    from: TWILIO_CALLER_ID,
    url: 'https://demo.twilio.com/welcome/voice' // A URL that produces an XML document (TwiML) which contains instructions for the call
  }, function(err, responseData) {

      //executed when the call has been initiated.
      console.log(responseData.from); // outputs "+14506667788"

      var resp = new client.TwimlResponse();

      resp.say('Welcome to Acme Customer Service!')
        .gather({
          action:'http://www.example.com/callFinished.php',
          finishOnKey:'*'
      }, function() {
          this.say('Press 1 for customer service')
              .say('Press 2 for British customer service', { language:'en-gb' });
      });
  });
};

1 个答案:

答案 0 :(得分:3)

Twilio开发者传道者在这里。

您可以使用此功能,但您不希望在回调client.makeCall的回调中创建TwiML响应。 responseData表示Twilio系统中的呼叫。

您需要做的是提供一个makeCall功能的URL,该功能托管一些将呼叫连接到另一个电话号码的TwiML。目前您已准备好演示网址,因此您需要将其指向您拥有的网址。

有一个非常好的深度教程,介绍如何在Twilio网站上完成所有这些,你可能会发现它有所帮助。 You can find the tutorial here,试一试,如果有帮助请告诉我。