Asterisk Gateway Interface

Asterisk Gateway Interface (AGI) is a software interface and communications protocol for application level control of selected features of the Asterisk PBX.

AGI allows an external, user-written program, launched from the Asterisk dial plan via pipes to control telephony operations on its associated control and voice channels. It is similar to the CGI feature of web servers in allowing any language to be used for writing the external program which communicates with Asterisk via stdin and stdout.

While the initial feature set of AGI included only a procedural control of Asterisk operations via commands and response handshake, Enhanced AGI (EAGI) also provided out-of-band access to the incoming audio stream.

FastAGI is an extension to AGI which allows the external program to run at a separate network host to avoid the overhead of creating a new process for every call on the Asterisk server. It uses a TCP socket for communication to the external host which provides the function of an AGI service, in a manner of the client–server model. The default TCP port for FastAGI is 4573. Similar to HTTP uniform resource identifiers (URIs), FastAGI employs a URI format of.agi://hostname[:port][/program/path]

The AGI feature set of Asterisk is implemented as an Asterisk loadable module (res agi).

Software Interfaces

There are many libraries that greatly simplifies development process of AGI scripts. The most interesting of them is:

  1. phpagi
  2. Perl AGI Library
  3. CAGI
  4. NanoAGI
  5. PyST

Usage examples

Example for NanoAGI

  #include "src/agi.H"

  int main()
  {
     AGI agi;

     if(
       agi.cmd("stream file hello-world 0")
     < 0)
     {
       // cerr << agi.err;
       return -1;
     }
     agi.cmd("hangup");

     return 0;
  }

Compile it with Make utility

 $ make

Move compiled binary into ${astagidir}. Then add following into ${astetcdir}/extensions.conf and reload dialplan:

 exten => _100,1,AGI(scriptname)

External links

This article is issued from Wikipedia - version of the Thursday, March 03, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.