login | register
Wed 01 of Aug, 2007 [09:14 UTC]

voip-info.org

Search with Google
Search this site with Google. Results may not include recent changes.

Web www.voip-info.org
Shoutbox
  • Aykut, Wed 01 of Aug, 2007 [07:53 UTC]: Hi all, does anybody know about Thomson ST2030 SIP phone. I have upgraded it to latest version (1.56) but "Hold" and "Conf" features are not working after the upgrade ?? Do you know any solution or do you have Ver. 1.52 ?? Where can I find it?
  • Edward J Brown, Tue 31 of Jul, 2007 [23:33 UTC]: Has anybody experienced Choppy voice quality when using a Linksys SPA942 in an Asterisk Conference bridge? It works fine with my polycom and Cisco, but sucks with my Linksys.
  • www.astawerks.com, Fri 27 of Jul, 2007 [18:00 UTC]: does anyone use asterisk on top of clark connect? does it work good?
  • simon, Fri 27 of Jul, 2007 [14:16 UTC]: Hi All, Has anyone here managed to get the Cisco79x1 to successfully fail over to the backup proxy. I have 2 asterisk servers , handsets all register and function, except that backup proxy function doesn't work. Any working example would be very apprecia
  • Matthew Richmond, Thu 26 of Jul, 2007 [03:40 UTC]: using the page() application to page across our building...often the meetme conferences don't disconnect after the caller hangs up. Anyone else having this problem. (using Polycom phones)
  • Matthew Richmond, Wed 25 of Jul, 2007 [02:58 UTC]: thanks Nicholas Blasgen! I haven't worked with AGI before, but there's always a first! Thanks again!
  • Nicholas Blasgen, Tue 24 of Jul, 2007 [19:18 UTC]: Matthew Richmond, AGI will handle all that for you.
  • sam, Mon 23 of Jul, 2007 [16:39 UTC]: need help - certain voicemail extension will stop working and recording voicemail on asterisk - anyone know why and how to fix it? Thanks
  • john haji, Mon 23 of Jul, 2007 [14:55 UTC]: free calls to pakistan
  • bong, Sat 21 of Jul, 2007 [19:09 UTC]: hi good day to all can anyone help me how to configured the nortel sip to the signaling server and how to activate in mobile w/ sip compatible without mcs
Server Stats
  • Execution time: 0.25s
  • Memory usage: 2.29MB
  • Database queries: 29
  • GZIP: Disabled
  • Server load: 3.63

Asterisk AGI

AGI

AGI is the Asterisk Gateway Interface, an interface for adding functionality to asterisk with many different programming languages. Perl, PHP, C, Pascal, Bourne Shell - it's your choice, really.

  • AGI may control the dialplan, called in extensions.conf
  • EAGI gives the application the possibility to access and control the sound channel in addition to interaction with the dial plan
  • FastAGI can be used to do the processing on a remote machine
  • DeadAGI gives access to a dead channel, after hangup

New in Asterisk v1.2.11: GET VARIABLE can now retrieve global variables (see bug 7609)
New in Asterisk v1.2: CallerID is reported with agi_callerid and agi_calleridname instead of a single parameter holding both. The agi_callerid previously held the value "Name"<Number> and the agi_calleridname was not present. In v1.2, agi_callerid has Number and the agi_calleridname has Name.

For debugging purposes you can type "agi debug" on the CLI.

Applications

  • AGI, DeadAGI, and EAGI: Applications to use in extensions.conf
  • FastAGI: Allows running of AGI applications on a remote machine (improves performance for Asterisk)

Dialing out

If the AGI application dials outward by executing Dial, control over the call returns to the dialplan and the script loses contact with the Asterisk server. The script continues to run in the background by itself and is free to clean up and do post-dial processing.

If you want your application to initiate a call out without being started through the dialplan:

AGI Execution Environment


You can pass arguments to an AGI script, like so:
 AGI(script.agi|arg1|arg2|...)

The AGI script can sends Asterisk special AGI commands on standard output and read the result on standard input. The result takes this form:

  200 result=X

where X is generally 1 for success and 0 for failure. Some commands return additional name=value pairs. Some return a string value in parentheses.

To list the special commands, type "agi show" in the Asterisk command line interface.

When Asterisk starts an AGI script, it feeds the channel variables to the script on standard input. The variable names are prefixed with "agi_" and are separated from their values by a colon and a space. Though the actual channel variables may be in the upper case, the names passed to an AGI script are all lower case. Also, some channel variable names as passed to AGI script differ from the current variable names used in the dial plan.

Here are some of the variables passed to AGI scripts:

  • agi_channel — calling channel
  • agi_callerid — CALLERID(num)
  • agi_calleridname — CALLERID(name)
  • agi_context — dialplan context from which script was called
  • agi_extension — dialplan extension from which script was called
  • agi_priority — dialplan priority from which script was called
  • agi_language — CHANNEL(language)

Global variables are not passed to the AGI script in this manner. You must get them using the "get variable" AGI command.

An AGI script is also passed a number of environment variables which point to file-system directories which contain Asterisk files. These are:
  • AST_CONFIG_DIR
  • AST_CONFIG_FILE
  • AST_MODULE_DIR
  • AST_SPOOL_DIR
  • AST_MONITOR_DIR
  • AST_VAR_DIR
  • AST_DATA_DIR
  • AST_LOG_DIR
  • AST_AGI_DIR
  • AST_KEY_DIR
  • AST_RUN_DIR

Return value

AGI script returns the following status in variable "AGISTATUS":
  • SUCCESS
  • FAILURE
  • HANGUP

AGI commands




Libraries and Frameworks

Java


Perl


PHP


Python


Ruby


C

  • CAGI: A C API for AGI. Based on PHPAGI.
  • Quivr: A C API for AGI. ANSI C AGI Library.

.NET


Bash and Ash

  • Bash AGI: A Bash script that sets the callerID name from NANPA data for the NPA-NXX.
  • MacinTalk AGI: A Bash script that does text to voice with MacinTalk.
  • The distribution package of the LCDial.sh AGI script contains a sh-agi.inc file providing primitives, such as sh_agi_cmd, sh_agi_getvariable and sh_agi_log, to simplify the coding of AGI scripts for the bash and ash shell interpreters.

Notes


Fork and continue dialplan

If you don't want Asterisk to wait until the script finishes you can fork the script off to return to dialplan excution: Here's how to accomplish this in PERL:
 open STDOUT, '>/dev/null';
 fork and exit; 

CLI output

>>For some reason, my AGI perl scripts cannot write to the CLI console using
>>standard error. I ran the agi-test.agi test script that came with asterisk
>>and verified that the problem was not with the code. Asterisk is always
>>started with 4 or more v's, yet this the CLI output does not show up. Have
>>there been any major changes to AGI in the cvs-head? I am using Asterisk
>>CVS-D2005.08.05.
>
>This is a known problem. Asterisk will only send STDERR from AGI
>scripts to the actual console Asterisk is running on. You have to
>switch to the actual console Asterisk is running on (tty9 I think) or
>start asterisk in the foreground with "asterisk -cvvv".
>
>It's a minor issue for most people.

We start asterisk under a detached screen with GNU screen. We use the
'L' flag to log to a text file if we want. Then we can "screen -r" to
the actual asterisk CLI any time we want.

 /usr/bin/screen -L -d -m -S asterisk /usr/sbin/asterisk -vvvvvvvvvvvvvvvvvvvvvgc

See http://www.gnu.org/software/screen/


Diverse

  • Using the verbose comand in an AGI you can feed information back to the console (the CLI ) in the same way that applications do. So by specifying different information to be returned at various verbosity levels the AGI will produce results similar to those of Asterisk applications. Make sure you read the return of the VERBOSE command (just like with any other AGI command) before issuing another AGI command. Be aware that VERBOSE will give trouble with quoted strings as e.g. in CALLERID (verbose will cut the string after the first space character).
  • The EAGI extension will let you receive sound from the channel into your application. It will not let you send sound. EAGI is intended to allow you to write a script that passes sound to an external application - such as the Sphinx speech-to-text/speech recognition application (as the example script included with asterisk does). Your EAGI application must also listen for a text response. In the case of Sphinx this would be a string representing the captured speech.
  • Always use AGI unless you specifically need EAGI functionality - unpredictable results may otherwise be obtained.
  • Commands such as "send text" may cause your script to fail if accessed from a phone that has no capability for the requested media type.
  • GET VARIABLE: Does not work with global variables. Does not work with some variables that are generated by modules.
  • Additional commands (PUT SOUNDFILE, GET SOUNDFILE,...) here: http://free.oxymium.net/Asterisk/AGIAddOns/


Tutorials


I wrote up a paper on the basics of AGI programming that can be found here. It goes over the basics and includes a sample program. Feedback is welcome!

Created by oej, Last modification by Mike Vincent on Fri 27 of Jul, 2007 [22:36 UTC]

Comments Filter
Edit

more info

by Anonymous on Sunday 17 of October, 2004 [04:44:45 UTC]
anyone have more detailed info on how to get the card working with mysql?

Edit

Database setup?

by Anonymous on Sunday 16 of May, 2004 [16:38:23 UTC]
how about a mysqldump of a database that'll work with the agi-ccard.agi app?

Please update this page with new information, just login and click on the "Edit" or "Add Comment" button above. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

Sponsored by:

Terms of Service Privacy Policy
© 2003-2007 Arte Marketing, Inc.

Powered by bitweaver