计划我的程序:有人打电话给Twilio号码,然后我的手机就被叫了。只要我不接受电话,来电者应该听到音乐或类似的东西,如果我拿起,会开始会议。
目前: 有人打电话给这个号码,然后用音乐排队,然后我的手机就被叫了。听起来不错,但是当我拿起时我们没有联系。
所以我想我不能正确地了解Twilio会议是如何运作的,如果你有一些建议如何逐步完成这项工作。
答案 0 :(得分:2)
Twilio开发者传道者在这里。
好的,你正在使用Node.js构建,我知道我已经在其他问题中看到了你的代码,但我将从头开始这个。
使用Twilio,您描述的流程应如下所示。
让我们看看我们如何在Node.js Express应用程序中执行此操作:
您需要两条路线,一条路线将接收初始请求,另一条路线将响应您接听电话时发出的请求。查看下面的代码和评论。
var express = require("express");
var bodyParser = require("body-parser");
var twilio = require("twilio");
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
var client = twilio(YOUR_ACCOUNT_SID, YOUR_AUTH_TOKEN);
// This is the endpoint your Twilio number's Voice Request URL should point at
app.post('/calls', function(req, res, next) {
// conference name will be a random number between 0 and 10000
var conferenceName = Math.floor(Math.random() * 10000).toString();
// Create a call to your mobile and add the conference name as a parameter to
// the URL.
client.calls.create({
from: YOUR_TWILIO_NUMBER,
to: YOUR_MOBILE_NUMBER,
url: "/join_conference?id=" + conferenceName
});
// Now return TwiML to the caller to put them in the conference, using the
// same name.
var twiml = new twilio.TwimlResponse();
twiml.dial(function(node) {
node.conference(conferenceName, {
waitUrl: "http://twimlets.com/holdmusic?Bucket=com.twilio.music.rock",
startConferenceOnEnter: false
});
});
res.set('Content-Type', 'text/xml');
res.send(twiml.toString());
});
// This is the endpoint that Twilio will call when you answer the phone
app.post("/join_conference", function(req, res, next) {
var conferenceName = req.query.id;
// We return TwiML to enter the same conference
var twiml = new twilio.TwimlResponse();
twiml.dial(function(node) {
node.conference(conferenceName, {
startConferenceOnEnter: true
});
});
res.set('Content-Type', 'text/xml');
res.send(twiml.toString());
});
让我知道这是否有帮助。
<强>更新强>
在最新版本的Twilio Node.js库中,您无法使用twilio.TwimlResponse
。相反,语音和消息传递有各自的类。在这个例子中的行
var twiml = new twilio.TwimlResponse();
应更新为:
var twiml = new twilio.twiml.VoiceResponse();
答案 1 :(得分:1)
我自己解决了这个问题,你需要用会议回答两个参与者,当对方接听电话时它会自动启动
示例
resp.say({voice:'woman'}, 'Welcome to our hotline. This could take a moment, please wait.')
.dial({},function(err){
this.conference('example');
});