我正在尝试创建一个 Web 应用程序,其中:
我通过 twilio 从浏览器应用程序向电话号码发出呼出电话。我将 Twilio Client(js) v 1.10.1 用于浏览器应用程序。后端 webhook 使用 Twilio 的 Dial and Number 动词用 Java 编写。我能够使用 twilio 的可编程语音来实现它。
伪代码如下
前端代码
let device = require('twilio-client').Device; let outboundCall = ''; const twilioInit = () => { // twilio client initialization logic goes here } // on phone icon click i am calling the below method const makeOutboundCall = () => { outboundCall = device.connect({ To: TO_NUMBER // The first to number }); }
后端代码 - 服务器端(webhook)
@RequestMapping(value="/callCustomers", produces= "text/xml") public String callByBrowserToMobile(@RequestParam String ApplicationSid, @RequestParam String ApiVersion, @RequestParam String Called, @RequestParam String Caller, @RequestParam String CallStatus, @RequestParam String To, @RequestParam String From, @RequestParam String CallSid, @RequestParam String Direction, @RequestParam String AccountSid) { Number number = new Number.Builder(To).build(); Dial dial = new Dial.Builder().answerOnBridge(true).number(number).callerId(myTwilioNumber).build(); VoiceResponse response = new VoiceResponse.Builder().dial(dial).build(); logger.info(response.toXml()); return response.toXml(); }
其次,一旦连接了出站呼叫,我想将更多人添加到正在进行的呼叫中。
如何达到第二个要求?
编辑: 我尝试使用以下代码进行电话会议:
@RequestMapping(value = "/callMobile", produces = "text/xml")
public String callByBrowserToMobile(@RequestParam String ApplicationSid, @RequestParam String ApiVersion,
@RequestParam String Called, @RequestParam String Caller, @RequestParam String CallStatus,
@RequestParam String To, @RequestParam String From, @RequestParam String CallSid,
@RequestParam String Direction, @RequestParam String AccountSid) {
LOG.info("Call by browser to mobile");
String voiceCallBackUri = new StringBuilder(
env.getProperty("twilio.exposed.uri").concat("/conferenceCallBack")).toString();
String joinConferenceUri = new StringBuilder(
env.getProperty("twilio.exposed.uri").concat("/joinConference")).toString();
String fromNumber = "+xxxxxxxxx35"; // Bought Twilio Number
Call call = Call.creator(
new com.twilio.type.PhoneNumber("+"+To),
new com.twilio.type.PhoneNumber(fromNumber),
URI.create(joinConferenceUri))
.setMethod(HttpMethod.GET)
.setStatusCallback(URI.create(voiceCallBackUri))
.setStatusCallbackMethod(HttpMethod.POST)
.create();
Conference.Builder conferenceBuilder = new Conference.Builder("My Conference");
Dial dial = new Dial.Builder().conference(conferenceBuilder.build()).build();
VoiceResponse twiml = new VoiceResponse.Builder().dial(dial).build();
return twiml.toXml();
}
@RequestMapping("/joinConference")
public String joinConference() {
LOG.info("joinConference");
Conference.Builder conferenceBuilder = new Conference.Builder("My Conference");
Dial dial = new Dial.Builder().conference(conferenceBuilder.build()).build();
VoiceResponse twiml = new VoiceResponse.Builder().dial(dial).build();
return twiml.toXml();
}
@RequestMapping("/conferenceCallBack")
public void conferenceCallBack(@RequestParam String Called, @RequestParam String ToState,
@RequestParam String CallerCountry, @RequestParam String Timestamp, @RequestParam String Direction,
@RequestParam String CallbackSource, @RequestParam String SipResponseCode, @RequestParam String CallerState,
@RequestParam String ToZip, @RequestParam String SequenceNumber, @RequestParam String To,
@RequestParam String CallSid, @RequestParam String ToCountry, @RequestParam String CallerZip,
@RequestParam String ApiVersion, @RequestParam String CalledZip,@RequestParam String CallStatus,
@RequestParam String CalledCity, @RequestParam String Duration, @RequestParam String From,
@RequestParam String CallDuration, @RequestParam String AccountSid, @RequestParam String CalledCountry,
@RequestParam String CallerCity, @RequestParam String Caller, @RequestParam String FromCountry,
@RequestParam String ToCity, @RequestParam String FromCity, @RequestParam String CalledState,
@RequestParam String FromZip, @RequestParam String FromState) {
LOG.info("conferenceCallBack");
}
使用上面的代码进行会议,呼叫者(浏览器应用程序)会听到等待电话会议的音乐并且被呼叫者接听电话,但是当被接听时只会听到会议名称并且被呼叫者的呼叫断开。请指导查找问题。