The Hitchhiker's Guide to Asterisk | ||
---|---|---|
<<< Previous | Scripting with the Asterisk Gateway Interface (AGI) | Next >>> |
Specific examples for languages can be found at http://home.cogeco.ca/~camstuff/agi.html.
Perl's propensity for data manipulation and quick scripting make it a very popular choice for AGI scripting. To make Perl AGI programming even easier, James Golovich created Asterisk::AGI, a module designed for simplifying AGI interaction. Asterisk::AGI is available from the author's web page at http://asterisk.gnuinter.net/.
Without using Asterisk::AGI, this is what a simple AGI script to tell a user their phone number would look like.
#!/usr/bin/perl -w use strict; $|=1; #Get the initial data my %input; while(<STDIN>) { chomp; last unless length($_); if (/^agi_(\w+)\:\s+(.*)$/) { $input{$1} = $2; } } print "stream file the-number-is"; print "say digits $input{callerid}"; print "exec WaitMusicOnHold 2"; print "hangup"; |
Using Asterisk::AGI, we can simplify the previous script a bit:
#!/usr/bin/perl -w use strict; use Asterisk::AGI; $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); #Read in the initial data $AGI->stream_file('the-number-is'); $AGI->say_digits($input{callerid}); $AGI->exec('WaitMusicOnHold','2'); $AGI->hangup(); |
<<< Previous | Home | Next >>> |
AGI Basics | Up | EAGI |