我正在开发一个java应用程序,它应该能够使用java - asterisk调用另一方并从用户获得DTMF值。我使用AMI的originate
命令,卡住了。我可以呼叫另一方,但接听后立即结束呼叫并返回success
。
如何发起调用并读取DTMF值?
OriginateAction originateAction = new OriginateAction();
originateAction.setChannel("SIP/1001");
originateAction.setContext("from-internal");
originateAction.setExten("1002");
originateAction.setCallerId("Server");
originateAction.setPriority(1);
originateAction.setTimeout(30000);
// connect to Asterisk and log in
managerConnection.login();
//send the originate action and wait for a maximum of 30 seconds for Asterisk
// to send a reply
ManagerResponse response= managerConnection.sendAction(originateAction, 30000);
AMI中的Originate操作允许您通过TCP连接发送请求,以便Asterisk进行呼叫。这是从自定义应用程序发起调用的最常用方法。解决方案中提供的示例首先让Asterisk对SIP/1001
进行新的调用。如果电话在30秒内没有应答,通话将被中止。如果呼叫被应答,则连接到拨号计划中from-internal
上下文中的分机1002。在调用1002扩展后,我需要读取DTMF是这样的:
public class HelloAgiScript extends BaseAgiScript {
public void service(AgiRequest request, AgiChannel channel) throws AgiException
{
// Answer the channel...
answer();
// ...say hello and get DTMF data...
String data = getData("welcome");
// ...and hangup.
hangup();
}
}
点击这里查看原来的HelloAgiScript