【问题标题】:Can we call a number in middle of a conference call in Twilio?我们可以在 Twilio 的电话会议中拨打电话吗?
【发布时间】:2018-05-01 07:45:45
【问题描述】:

我是这个领域的新手。来提问。我想在电话会议期间拨打一个号码并将该参与者添加到当前会议。 我已经尝试了在 Java 中给出here 的会议示例代码。有没有办法收集输入然后拨打号码并将参与者添加到同一个会议。

这是我尝试过的。我创建了一个会议,它将返回以下响应

<Response>
<Dial hangupOnStar="true">
<Conference startConferenceOnEnter="true" endConferenceOnExit="true">My Conference</Conference>
</Dial>
<Gather timeout="10" action="/twilio-tut/add/participant?confName=My%20Conference" finishOnKey="#">
<Say>Please enter the number you want to connect followed by hash key.</Say></Gather>
</Response>

现在会议中的一位参与者说A按* 并拨打另一个他想加入会议的人的号码。

现在Gather动词的动作,我正在拨打一个号码,代码如下所示

Number number = 
                    new Number.Builder(some_valid_phone_number)
                    .statusCallback("https://xxxxxxx.ngrok.io/twilio-tut/to/conference")
                    .statusCallbackMethod(Method.POST)
                    .statusCallbackEvents(Arrays.asList(Event.ANSWERED))
                    .build();

            Dial dial = new Dial.Builder()
                    .number(number)
                    .conference(new Conference.Builder(conferenceName).build())
                    .build();

            twiml = new VoiceResponse.Builder().dial(dial)
                    .build();

在 statusCallback 上,我正在更新呼叫以重定向到呼叫者和被呼叫者的会议,其中呼叫者是通过按 * 离开会议的人,即 A 并且被呼叫者是 some_valid_phone_number 。代码如下所示

Call callee = Call.updater(callSid)
                    .setUrl("https://xxxxx.ngrok.io/twilio-tut/voice").setMethod(HttpMethod.POST).update();
            Call caller = Call.updater(parentCallSid)
                    .setUrl("https://xxxxx.ngrok.io/twilio-tut/voice").setMethod(HttpMethod.POST).update();

以上代码转移被调用者并使用异常断开调用者

com.twilio.exception.ApiException: Call is not in-progress. Cannot redirect.

我想做的是A拨打其他号码,最后他们将连接到同一个会议。 A 应该能够呼叫其他号码并将它们添加到同一个会议中。我正在使用手机连接号码。

提前致谢。

【问题讨论】:

    标签: java twilio conference


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    您遇到的问题是您试图在 TwiML 中执行两个拨号以响应 &lt;Gather&gt;。与其将&lt;Dial&gt; 和&lt;Number&gt; 与您使用&lt;Gather&gt; 拨打的号码联系起来,不如使用create that call using the REST API 并使用TwiML 将电话上的人引导回原始会议。

    为了把它分成清晰的步骤,它应该是这样的:

    1. 用户拨打 Twilio 号码
    2. TwiML 响应,使用 hangUpOnStar 将用户添加到会议
    3. 用户按下星号,Gather 要求拨打号码
    4. 在对来自 Gather 的号码的响应中,使用 REST API 创建调用并将调用定向到原始入站 URL(“/conference”)
    5. 在对 Gather 操作的响应中,返回 TwiML 以将原始呼叫者返回到会议(重定向到原始入站 URL)

    我不是 Java 开发人员,所以这可能是错误的,但你想要的东西看起来有点像这样:

    @WebServlet("/dial/participant")
    public class AddParticipantToConference extends HttpServlet {
    
        public static final String MODERATOR = System.getenv("MY_PHONE_NUMBER");
        public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
        public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
    
        @Override
        protected void doPost(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
                throws IOException {    
            String selectedOption = servletRequest.getParameter("Digits");
    
            VoiceResponse twiml;
    
            if(selectedOption != null){
                Call call = Call.creator(new PhoneNumber("+" + selectedOption), new PhoneNumber(MODERATOR),
            new URI("https://example.com/conference")).create();
            }
    
            twiml = new VoiceResponse.Builder().redirect("/conference").build();
    
            servletResponse.setContentType("text/xml");
    
            try {
                servletResponse.getWriter().print(twiml.toXml());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

    您现在不需要 statusCallback。

    让我知道这是否有帮助

    【讨论】:

    • 谢谢你,菲尔。我可以将参与者添加到会议。 :)
    【解决方案2】:

    这里是 Twilio 员工。

    你可以!您可以做的是使用 REST API 进行出站呼叫,并让该呼叫返回带有 Conference 动词和相同会议名称的 TwiML - 例如,如果您创建了一个名为 conference1 的电话会议,您会想要使用类似于以下内容的 TwiML 进行响应:

    <Response>
        <Dial>
            <Conference>conference1</Conference>
        </Dial>
    </Response>
    

    这会将呼出呼叫连接到现有会议,或创建它。

    如果您使用&lt;Gather&gt; 动词作为现有呼叫的输入,那么您也可以使用此解决方案。您想要重定向调用流程,而不是创建一个全新的调用,因此只需在 Gather 回调中返回此 TwiML。

    如果您一直跟踪会议 SID,您还可以通过创建出站电话会议 (sample code here) 以编程方式添加它们。与 TwiML 类似,如果电话会议不存在,Twilio 将创建它;如果确实存在,Twilio 会将人添加到其中。

    【讨论】:

    • 谢谢您,瑞奇,您的回复。非常感谢您的努力。
    • 嗨,Ricky,你能帮忙this
    猜你喜欢
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    相关资源
    最近更新 更多