Twilio 出站呼叫 - 向现有呼叫添加更多人
Twilio Outbound call - Add more people to existing call
我正在尝试创建一个 Web 应用程序,其中:
我通过 twilio 从浏览器应用程序向 phone 号码拨出电话。我正在为浏览器应用程序使用 Twilio Client(js) v 1.10.1。
后端 webhook 使用 Twilio 的拨号和数字动词以 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");
}
使用上面的代码进行会议,呼叫者(浏览器应用程序)听到电话会议的等待音乐,被呼叫者接听电话但是当被选择时只听到会议名称并且被呼叫者的呼叫断开。请指导查找问题。
您可以使用座席会议。
这是示例代码和如何工作的高级图片
https://www.twilio.com/blog/multi-party-calls-voip-gsm-programmable-voice
这里是 Twilio 开发人员布道者。
您没有将 /joinConference
路由作为 text/xml
提供,因此 Twilio 将其读取为 text/plain
并将其视为 <Say>
。
我认为您需要将 produces = 'text/xml'
添加到 RequestMapping
,如下所示:
@RequestMapping("/joinConference", produces = "text/xml")
如果有帮助请告诉我。
我正在尝试创建一个 Web 应用程序,其中:
我通过 twilio 从浏览器应用程序向 phone 号码拨出电话。我正在为浏览器应用程序使用 Twilio Client(js) v 1.10.1。 后端 webhook 使用 Twilio 的拨号和数字动词以 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");
}
使用上面的代码进行会议,呼叫者(浏览器应用程序)听到电话会议的等待音乐,被呼叫者接听电话但是当被选择时只听到会议名称并且被呼叫者的呼叫断开。请指导查找问题。
您可以使用座席会议。 这是示例代码和如何工作的高级图片 https://www.twilio.com/blog/multi-party-calls-voip-gsm-programmable-voice
这里是 Twilio 开发人员布道者。
您没有将 /joinConference
路由作为 text/xml
提供,因此 Twilio 将其读取为 text/plain
并将其视为 <Say>
。
我认为您需要将 produces = 'text/xml'
添加到 RequestMapping
,如下所示:
@RequestMapping("/joinConference", produces = "text/xml")
如果有帮助请告诉我。