AGI Basics

Communication between the AGI script and Asterisk is accomplished through the standard input, output, and error file descriptors of the AGI script. At initialization, Asterisk sends several important pieces of initialization information to the AGI script. This data needs to be read before any commands are passed to Asterisk; otherwise, it will not be available.

Table 1. Initialization Data

NameSample ValueExplanation/Notes
agi_accountcode123Set by SetAccount in the dialplan
agi_callerid2128675309Remember, this may not always be a number
agi_channelSIP/1001-6476 
agi_contextdefault 
agi_dnid2890Dialed Number Identifier. More likely will show up as "unknown"
agi_enhanced0.0Value is 1.0 if started as an EAGI script
agi_extension100 
agi_languageen 
agi_priority1 
agi_rdnis2494The current referring DNIS number from the Zaptel ISDN subsystem.
agi_requestmyagi.agi???
agi_typeSIPCould also be ZAP, H323, etc.
agi_uniqueid1077328545.0Note that uniqueids are based on Unix time.

Commands are passed to Asterisk in the format [command] <arg1> <arg2> ... <argn>. A list of available commands may be fetched with the Asterisk Console command show agi.

The standard error channel can be used to send messages to the Asterisk console. The test AGI scripts included with Asterisk contain an example of this behavior.