[英]How to get Twilio conference name in client after it joins the conference?
[英]how to start a conference with twilio?
规划我的程序:有人在拨打Twilio号码,然后我在手机上接到电话。 只要我不接听电话,呼叫者就应该听到音乐或类似的声音,如果我接听电话,会议应该开始。
此刻:有人在拨打电话并排队听音乐,然后我的手机被拨打了。 听起来还不错,但是当我上车时,我们无法建立联系。
所以我想我不太了解Twilio会议的工作方式,可能您对如何逐步完成此工作有一些建议。
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();
我自己解决了这个问题,您需要用会议来回答两个与会者,会议将在其他人接听电话后自动开始
例
resp.say({voice:'woman'}, 'Welcome to our hotline. This could take a moment, please wait.')
.dial({},function(err){
this.conference('example');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.