1

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

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

<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 press*并拨打了他想要添加到会议中的另一个人的号码。

现在在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 上,我正在更新呼叫以重定向到呼叫者和被呼叫者的会议,其中呼叫者是通过按*ie 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应该能够呼叫其他号码并将它们添加到同一个会议中。我正在使用手机连接号码。

提前致谢。

4

2 回答 2

2

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

您遇到的问题是您试图在 TwiML 中执行两个拨号以响应<Gather>. 您应该使用 REST API 创建该呼叫并使用 TwiML 将电话上的人引导回原始会议,而不是使用拨打的<Dial>号码。<Number><Gather>

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

  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。

让我知道这是否有帮助

于 2017-11-26T23:00:58.900 回答
2
于 2017-11-18T00:51:13.380 回答