我是这个领域的新手。来提问。我想在电话会议期间拨打一个号码并将该参与者添加到当前会议中。我曾尝试给会议的样本代码在这里中的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按下*
并拨打了另一个他想要添加到会议中的人的号码。
现在关于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应该能够呼叫其他号码并将它们添加到同一个会议中。我正在使用手机连接号码。
提前致谢。
Twilio 开发人员布道者在这里。
您遇到的问题是您试图在 TwiML 中执行两次拨号以响应<Gather>
. 而不是让一个<Dial>
与<Number>
你同拨的号码<Gather>
,您应该创建一个使用REST API该呼叫并使用TwiML直接在手机放回原会议的人。
要把它变成清晰的步骤,它应该是这样的:
我不是 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 了。
让我知道这是否有帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句