0

我正在尝试创建一个 Web 应用程序,其中:

  1. 我通过 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();    
    }
    
  2. 其次,一旦连接了出站呼叫,我想将更多人添加到正在进行的呼叫中。

如何达到第二个要求?

编辑: 我尝试使用以下代码进行电话会议:

@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");
}

使用上面的代码进行会议,呼叫者(浏览器应用程序)会听到等待电话会议的音乐并且被呼叫者接听电话,但是当被接听时只会听到会议名称并且被呼叫者的呼叫断开。请指导查找问题。

4

2 回答 2

1

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

您没有为您的/joinConference路线提供服务,text/xml因此 Twilio 将其视为text/plain并将其视为<Say>.

我认为您需要添加produces = 'text/xml'到 中RequestMapping,如下所示:

@RequestMapping("/joinConference", produces = "text/xml")

让我知道这是否有帮助。

于 2020-09-24T05:00:15.417 回答
0

您可以使用代理会议。这是示例代码和其工作原理的高级图片 https://www.twilio.com/blog/multi-party-calls-voip-gsm-programmable-voice

于 2020-09-14T23:04:20.597 回答