Asterisk-Java 1.0.0 includes support for implementing AGI scripts in the scripting language of your choice. You still have the benefit of running on the JVM but for the implementation of your script you can now choose your favorite language.
I’ve prepared a small demo script that counts down from ten to zero. Then it plays a beep and waits for DTMF input to read the digit you’ve pressed back to you. You can exit by pressing star (*) or pound (#). To show you how this script looks like in the different languages it is implemented three times: In Groovy, JavaScript and PHP.
To get started just download the binary distribution of Asterisk-Java. Unpack it and run the asterisk-java.jar file from the unpacked directory.
$ cd asterisk-java-1.0.0-SNAPSHOT $ java -jar asterisk-java.jar May 13, 2009 1:26:16 AM org.asteriskjava.fastagi.DefaultAgiServer startup INFO: Listening on *:4573.
The AGI scripts are put into the agi directory. There you’ll also find the demo.groovy, demo.js and demo.php files. The lib directory contains additional libraries required to execute the scripts.
In addition to the functions provided by the scripting language Asterisk-Java adds two variables:
- request
- the request data including the dialed extension, the caller id, channel name, parameters and more
- channel
- for interacting with Asterisk, e.g. to stream files, receive DTMF digits or execute dialplan applications
Modify your dialplan and add extensions for the demo scripts:
exten => 2000,1,Agi(agi://localhost/demo.groovy) exten => 2001,1,Agi(agi://localhost/demo.js) exten => 2002,1,Agi(agi://localhost/demo.php)
If you are not running Asterisk-Java on the same server as Asterisk replace localhost by the hostname of the machine running Asterisk-Java.
Note that you will need at least Java 6 to make use of the new scripting support.
Related posts:
Can I assume that this is based on JSR 223?
If so, then I may use any language listed here?
https://scripting.dev.java.net/
Or does this use some other mechanism?
Exactly. All you have to do to add more languages is to drop the corresponding jar file(s) into the lib folder. You already see the groovy, jruby, etc. jars there.
I think this is YART! (yet another revolutionary thing!).
Thanks very much, Stefan
I would like to know how to connect to mysql using resin and quercus through the scripting engine provided in the package.
BR,
Hi stefan.. I am getting the error “No script configured for the URL ‘agi://localhost/demo.js’ (script ‘demo.js’). should i include fastagi-mapping.properties file. If necessary what should be the content in that file. Thanks in advance.
No mapping properties file is required for scripting to work in 1.0.0-m2
But still i am getting the error. please help me.
Please use the users mailing list for community support: http://asterisk-java.org/development/mail-lists.html
I am just interested (i didn’t use JVM langs other than Java): what you think about:
http://clojure.org/
http://code.google.com/p/clojure-jsr223/
PS: Scala looks too Perl-ish for me ;-(