Question

I'm developing a java application that should be able to call another party using Java-Asterisk and get a DTMF value from user. I am using originate command of AMI and I'm stuck. I can call the other party but the call is ended immediately after answering and returns success.
How can I originate a call and read a DTMF value?

Was it helpful?

Solution

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);

The Originate action in the AMI allows you to send a request over a TCP connection for Asterisk to make a call. This is the most popular method for originating calls from custom applications. The example provided in the solution starts by having Asterisk make a new call to SIP/1001. If the phone does not answer within 30 seconds, the call will be aborted. If the call is answered, it is connected to extension 1002 in the from-internal context in the dialplan. After calling 1002 extension all i need to read DTMF is this:

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top