System information

CHAPTER 21
Asterisk Gateway Interface (AGI)
Caffeine. The gateway drug.
—Eddie Vedder
The Asterisk dialplan has evolved into a simple yet powerful programming interface
for call handling. However, many people, especially those with a prior programming
background, still prefer implementing their custom call handling in a different pro-
gramming language. Using another programming language may also allow you to uti-
lize existing code for integration with other systems. The Asterisk Gateway Interface
(AGI) allows the development of first-party call control in the programming language
of your choice. If you are not interested in implementing call control outside of the
native Asterisk dialplan, you may safely skip this chapter.
Quick Start
This section gives a quick example of using the AGI. First, add the following line
to /etc/asterisk/extensions.conf:
exten => 500,1,AGI(hello-world.sh)
Next, create a hello-world.sh script in /var/lib/asterisk/agi-bin/, as shown in Exam-
ple 21-1.
Example 21-1. A sample AGI script, hello-world.sh
#!/bin/bash
# Consume all variables sent by Asterisk
while read VAR && [ -n ${VAR} ] ; do : ; done
# Answer the call.
echo "ANSWER"
read RESPONSE
# Say the letters of "Hello World"
475