Preview: Support for AsyncAGI
Running AGI scripts through a Manager API connection
I've just finished adding support for Asynchronous AGI to Asterisk-Java. AsyncAGI allows you to run AGI scripts through a Manager API connection.
The way AsyncAGI is supported by Asterisk-Java hides the differences in the underlying communication from the users of our library. Your AGI scripts developed for FastAGI will run with AsyncAGI without a change.
To make use of AsyncAGI add the following extension to you dialplan:
exten => 1234,1,Agi(agi:async)
Create a simple AGI script, pass it to AsyncAgiServer and register the AsyncAgiServer as a listener to a ManagerConnection:
public class SampleScript extends BaseAgiScript
{
public void service(AgiRequest request, AgiChannel channel) throws AgiException
{
channel.streamFile("tt-monkeys");
}
public static void main(String[] args) throws Exception
{
ManagerConnection connection;
AsyncAgiServer agiServer;
connection = new DefaultManagerConnection("localhost", "manager", "pa55w0rd");
agiServer = new AsyncAgiServer(new SampleScript());
connection.addEventListener(agiServer);
connection.login();
while (true)
{
Thread.sleep(1000L);
}
}
}
To run the sample you need the latest snapshot of Asterisk-Java 1.0.0 (at least 20080404.222056-117) and Asterisk 1.6.0.
References
Re: Preview: Support for AsyncAGI
Is there a way to break a currently playing stream file command in async AGI? Async AGI seems to queue any other commands, including another Stream File command, while traditional AGI will immediately stop a currently playing streamed file to execute another AGI command. There are some times when the queueing is good, but other times when I want to immediately stop a playing file so that then next command is executed.
Re: Preview: Support for AsyncAGI
How do you interrupt a stream file command with traditional AGI? I think Async and traditional AGI both do not support this. With Async AGI and the Manager API you have the option to redirect the call to another extension however so that can be used as a workaround to interrupt an AGI.