Berk Olcay
Berk Olcay

Reputation: 161

Java how to dial in Asterisk

I want to call a number and play an audio file which is located in my computer.

There is an Asterisk server set up before. With the code in the below I managed to call a number and the extension plays a audio ("this is a test call") and hang ups. I know extension does this because the audio changes when I change it.

Maybe I can play any audio I want if I change the data in the extensions.conf. But the company I do my internship doesn't allow me to see or change Asterisk' files. So I have to do it in java.

Long story short, how can I dial a number and play the audio I want then hang up in java. I'm searching on the web for days but couldn't find anything. Please help me :(

public void run() throws IOException, AuthenticationFailedException,
        TimeoutException
{
    OriginateAction originateAction;
    ManagerResponse originateResponse;

    originateAction = new OriginateAction();
    originateAction.setChannel(number);
    originateAction.setContext(context);
    originateAction.setExten(extension);
    originateAction.setPriority(Integer.parseInt(priority));
    originateAction.setTimeout(new Integer(30000));

    managerConnection.login();                                              // connect to Asterisk and log in
    originateResponse = managerConnection.sendAction(originateAction, 30000);// send the originate action and wait for a maximum of 30 seconds for Asterisk to send a reply
    System.out.println(originateResponse.getResponse());                    // print out whether the originate succeeded or not
    managerConnection.logoff();                                             // and finally log off and disconnect

}

Upvotes: 2

Views: 1457

Answers (1)

QGA
QGA

Reputation: 3192

Have a look at this

You can use exec("Playback","your file") to play a file

public class ExampleCallIn extends BaseAgiScript {
  public void service(AgiRequest request, AgiChannel channel) throws AgiException {
    answer();
    exec("Playback", "tt-monkeys"); 
    hangup();
  }
}

the exec command can use any application defined by your asterisk server like Dial or Originate

Upvotes: 2

Related Questions