我目前正在使用 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' });
});
});
};
最佳答案
这里是 Twilio 开发者布道者。
您已完成此任务,但您不希望在对 client.makeCall
的调用的回调中创建 TwiML 响应。 responseData
是 Twilio 系统中调用的表示。
您需要做的是向 makeCall
函数提供一个 URL,该函数托管一些将调用连接到另一个电话号码的 TwiML。目前您已经有了演示 URL,因此您需要将其指向您拥有的 URL。
Twilio 网站上有一个非常好的深入教程,介绍如何完成所有这些工作,您可能会发现它对您有所帮助。 You can find the tutorial here ,尝试一下,如果有帮助请告诉我。
关于node.js - 如何使用 twilio 将两个匿名调用者连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26763267/