在下一个示例代码中,Twilio 将对话OPERATOR_PHONE_NUMBER放入CLIENT_PHONE_NUMBER,并记录通话。
但我不知道控制某些东西的代码应该是什么,一部或两部手机......:
不存在。
存在但沟通。
存在,不通信但不拾取。
存在,不交流,接听,对话发生。
import com.twilio.Twilio; import com.twilio.rest.api.v2010.account.Call; import com.twilio.rest.api.v2010.account.CallCreator; import com.twilio.type.PhoneNumber; import com.twilio.type.Twiml; public class SimpleCallWithRecording2 { private static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; private static final String AUTH_TOKEN = "9ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"; private static final String ASSIGNED_PHONE_NUMBER = "+15999999999999"; //Must be verified numbers in trial account private static final String OPERATOR_PHONE_NUMBER = "+34888888888"; private static final String CLIENT_PHONE_NUMBER = "+34777777777"; public static void main(String[] args) throws Exception { Twilio.init(ACCOUNT_SID, AUTH_TOKEN); PhoneNumber to = new PhoneNumber(OPERATOR_PHONE_NUMBER); PhoneNumber from = new PhoneNumber(ASSIGNED_PHONE_NUMBER); Twiml twiml = new Twiml( "<?xml version="1.0" encoding="UTF-8"?> " + "<Response> " + " <Say voice="woman">This is said by a robotic woman</Say> " + " <Dial> " + " <Number> " + CLIENT_PHONE_NUMBER + "</Number> " + " </Dial> " + "</Response> " ); CallCreator callCreator = Call.creator(to, from, twiml); callCreator.setRecord(true); Call call = callCreator.create(); System.out.println(call); }
}
在文档中,我看到可以用callCreator.setStatusCallback(URI.create("https://www.myapp.com/events"))
做一些事情,并对事件进行一些分类:">已启动",">响铃",">应答",">已完成"。但是我没有找到"在另一边"的代码,我的意思是极端 https://www.myapp.com/events¿?
您需要设置一个 rest 端点并将其设置为状态回调 url。 该网址将接收来自 twilio 的事件。
参考这个
编辑:如果还需要嵌套谓词中的事件,请为其定义属性"action"。
即
<Dial action="//callbackURL">
<Number> CLIENT_PHONE_NUMBER </Number>
</Dial>
这样你就会知道你的案例1,2,3,4。
要"控制"调用,您只需使用所需的 TwiML 响应回调请求。希望这能澄清。
edit2:您需要执行以下操作:
//handles callback url
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
{ //...
TwiMLResponse twiml = new TwiMLResponse();
String callSid = request.getParameter("CallSid");
//handle call specific data
switch(request.getParameter("CallStatus")){
case "no-answer": //construct twiML
case "ringing" ://...
}
//...
response.setContentType("application/xml");
response.getWriter().print(twiml.toXML());
}
参见: IVR - 示例