繁体   English   中英

如何与twilio开始会议?

[英]how to start a conference with twilio?

规划我的程序:有人在拨打Twilio号码,然后我在手机上接到电话。 只要我不接听电话,呼叫者就应该听到音乐或类似的声音,如果我接听电话,会议应该开始。

此刻:有人在拨打电话并排队听音乐,然后我的手机被拨打了。 听起来还不错,但是当我上车时,我们无法建立联系。

所以我想我不太了解Twilio会议的工作方式,可能您对如何逐步完成此工作有一些建议。

Twilio开发人员布道者在这里。

好的,您正在使用Node.js进行构建,我知道我在其他问题中也看到过您的代码,但是我将从头开始。

使用Twilio,您描述的流程应如下所示。

  • 人员拨打您的Twilio号码
  • Twilio向该号码的语音请求URL发出HTTP请求(指向您的应用程序)
  • 您的应用程序现在需要做两件事
    • 拨打您的手机号码
    • 播放音乐时将呼叫者置于会议中
  • 首先,您需要确定会议的名称
  • 然后要拨打您的电话号码,您的应用程序需要调用Twilio REST API以发起对您手机的呼叫
    • 您需要在此调用中提供一个回调URL,该回调URL也会使您也进入会议,可以通过在URL中包括会议名称作为参数来实现。
  • 您的应用程序还需要返回TwiML,以使用相同的会议名称将呼叫者放入会议中
  • 最后,当您接听电话时,Twilio将向发起呼叫时提供的URL发出HTTP请求
  • 这将要求您的URL,该URL应该以TwiML响应,以使您进入同一电话会议

让我们看看如何在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM