2014-05-11 89 views
1

我正在开发一个java应用程序,它应该能够使用Java-Asterisk调用另一方并从用户那里获得DTMF值。我正在使用AMI的originate命令,我卡住了。我可以给对方打电话,但电话在接听后立即结束并返回success
如何发起呼叫并读取DTMF值?如何使用asterisk-java发起呼叫并读取DTMF值?

+0

这个问题是完全一样的,你问2天前。 http://stackoverflow.com/questions/23472983/read-dtmf-using-asterisk-java。我很抱歉,你已经阅读了一些书来理解答案。 – arheops

+0

我相信我可以使用AMI的原始函数将用户连接到应用程序,但无法确定方式。文档非常薄弱。因为知道我使用通话文件,但我不喜欢它! – hkazemi

+0

我已经读过这本书:“Asterisk Cookbook - O'Reilly - 第2章 - 呼叫控制”。我必须能够使用发起功能 – hkazemi

回答

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

}

click here to see the original HelloAgiScript.