简体   繁体   English

我们可以在Twilio的电话会议中打一个电话吗?

[英]Can we call a number in middle of a conference call in Twilio?

I am new in this field. 我是这个领域的新手。 coming to question. 来质疑。 I want to call a number during the conference call and add that participant to the current conference. 我想在电话会议中打一个电话,并将该参与者添加到当前会议中。 I have tried a sample code for the conference given here in Java . 我已经尝试过使用Java 在此处给出的会议的示例代码。 Is there any way to gather the input then call the number and add the participant to the same conference. 有什么方法可以收集输入内容,然后拨打电话号码并将参与者添加到同一会议中。

here is what I tried. 这是我尝试过的。 I have created a conference and which will return the following response 我已经创建了一个会议,它将返回以下响应

<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>

Now One of the participants in conference say A press * and dialed a number of another person to whom he wants to add to the conference. 现在,参加会议的一位参与者说A*并拨打了他想添加到会议中的另一个人的号码。

Now on action of Gather verb, I am dialing a number the code as shown below 现在,在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();

On statusCallback, I am updating the call to redirect to conference for both caller and callee where caller is the one who left the conference by pressing * ie A and callee is some_valid_phone_number . 在statusCallback上,我正在更新呼叫以将呼叫者和被呼叫者都重定向到会议,其中呼叫者是通过按*即离开会议的那个呼叫者,即A ,被呼叫者是some_valid_phone_number Code is as shown below 代码如下所示

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();

above code transfer the callee and disconnect the caller with Exception 上面的代码转移了被调用者,并通过异常断开了与调用者的连接

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

What I want to do is A call some other number and finally they will connect to same conference. 我想要做的是调用一些其他的号码,最后他们将连接到同一个会议。 And A should be capable of calling other numbers and add them in same conference. 并且A应该能够呼叫其他号码并将其添加到同一会议中。 I am using mobile phone to connect the numbers. 我正在用手机连接号码。

Thanks in advance. 提前致谢。

Twilio employee here. Twilio的员工在这里。

You can! 您可以! What you can do is make an outbound call using the REST API, and have that call return TwiML with the Conference verb, and the same conference name - eg, if you've created a conference call named conference1 you'll want to respond with TwiML that looks something like: 您可以做的是使用REST API进行出站呼叫,并使该呼叫返回带有会议动词和相同会议名称的TwiML,例如,如果您创建了一个名为conference1电话conference1 ,则需要使用TwiML看起来像:

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

That will connect the outbound call to the existing conference, or create it. 这会将呼出电话连接到现有会议,或创建该会议。

If you're using the <Gather> verb for input on an existing call, then you can use this solution as well. 如果将<Gather>动词用于现有呼叫的输入,则也可以使用此解决方案。 You want to redirect the call flow, not create a whole new call, so just return this TwiML in the Gather callback. 您要重定向呼叫流,而不是创建一个新的呼叫,因此只需在Gather回调中返回此TwiML。

If you've kept track of the Conference SID, you could also programmatically add them by creating an outbound conference call ( sample code here ). 如果您一直跟踪会议SID,也可以通过创建呼出电话会议以编程方式添加它们( 此处为示例代码 )。 Similarly to the TwiML, if the conference call doesn't exist, Twilio will create it; 与TwiML相似,如果电话会议不存在,Twilio将创建它。 if it does exist, Twilio will add the person to it. 如果确实存在,Twilio会将人员添加到其中。

Twilio developer evangelist here. Twilio开发人员布道者在这里。

The issue you have is that you are trying to perform two dials within the TwiML in the response to the <Gather> . 您遇到的问题是,您试图在TwiML中执行两次拨号以响应<Gather> Rather than making a <Dial> with a <Number> to the number you dial with the <Gather> , you should create that call using the REST API and use the TwiML to direct the person on the phone back into the original conference. 与使用<Gather>拨打的号码而不使用<Number> <Dial>相比,您应该使用REST API创建该呼叫,并使用TwiML将电话上的人引导回原始会议。

To put that into clear steps, it should be something like this: 要将其分明,它应该是这样的:

  1. User calls Twilio number 用户拨打Twilio号码
  2. TwiML responds, adds user to conference with hangUpOnStar TwiML响应,使用h​​angUpOnStar将用户添加到会议中
  3. User presses star and Gather asks for a number to dial 用户按星号,然后Gather要求拨一个号码
  4. In the response to the number from Gather, create call using REST API and direct that call to the original inbound URL ("/conference") 在对来自Gather的电话号码的响应中,使用REST API创建呼叫并将该呼叫定向到原始入站URL(“ /会议”)
  5. In the response to the Gather action, return TwiML to return original caller to conference (with redirect to original inbound URL) 在对“收集”操作的响应中,返回TwiML以将原始呼叫者返回到会议(重定向到原始入站URL)

I'm not a Java developer, so this might be wrong, but you want something that looks a bit like this: 我不是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();
        }
    }
}

You don't need the statusCallback for this now. 您现在不需要statusCallback。

Let me know if that helps at all 让我知道这是否有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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