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
importtouched.agi.java.server.Server;
publicclassMain {
publicstaticvoidmain(String[] args) {
/** * Create an instance of Server. */Serverserver;
/** * Instantiate Server and assign it a port. */server = newServer(5000);
/** * Start the server. */server.Startup();
}
}Agi.java
importorg.asteriskjava.fastagi.AgiChannel;
importorg.asteriskjava.fastagi.AgiException;
importorg.asteriskjava.fastagi.AgiRequest;
importorg.asteriskjava.fastagi.BaseAgiScript;
importtouched.agi.java.methods.Methods;
publicclassAgiextendsBaseAgiScript {
@Overridepublicvoidservice(AgiRequestreq, AgiChannelctx) throwsAgiException {
Stringdata = 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 = AgiWith 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.jarIf 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
sylvesterstephenson028@gmail.com
Credits go to asterisk-java for the asterisk-java.jar file.