Touched-Agi-Java is an attempt to bring over the ease of use of touched-agi, but instead of JavaScipt/TypeScript you can write the AGIs in Java.
FastAGIServer.java
import touched.agi.java.server.Server;
public class Main {
public static void main(String[] args) {
/**
* Create an instance of Server.
*/
Server server;
/**
* Instantiate Server and assign it a port.
*/
server = new Server(5000);
/**
* Start the server.
*/
server.Startup();
}
}
Agi.java
import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.BaseAgiScript;
import touched.agi.java.methods.Methods;
public class Agi extends BaseAgiScript {
@Override
public void service(AgiRequest req, AgiChannel ctx) throws AgiException {
String data = ctx.getData("beep", 14000);
ctx.sayDigits(data)
}
In order to send requests to the Agi classes we need to tell the FastAgi which classes to send the Agi Requests to. This can be specified in the fastagi-mapping.properties file.
sample.agi = Agi
With the settings above the Agi URL will look like this.
agi://localhost:5000/sample.agi
Once you've created your Agi script and compiled it to a .jar file, it is now ready to be run on the server.
In order to run the Agi you can use the following command.
java -jar sample_agi.jar
If you would like to have the FastAgi script run in the background with a managed system, I would recommend using PM2 to manage the FastAgi Server.
Sylvester Stephenson
Credits go to asterisk-java for the asterisk-java.jar file.