Skip to Main Content
Asterisk: The Definitive Guide, 4th Edition
book

Asterisk: The Definitive Guide, 4th Edition

by Russell Bryant, Leif Madsen, Jim Van Meggelen
May 2013
Intermediate to advanced content levelIntermediate to advanced
843 pages
23h 50m
English
O'Reilly Media, Inc.
Content preview from Asterisk: The Definitive Guide, 4th Edition

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 programming language. Using another programming language may also allow you to utilize 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 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 Example 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"
echo 'SAY ALPHA "Hello World" ""'
read RESPONSE

exit 0

Now, call extension 500 with AGI debugging turned on, and listen to Allison spell out “Hello World”:

*CLI> agi set debug on
AGI Debugging Enabled

    -- Executing [500@phones:1] AGI("SIP/0004F2060EB4-00000009", 
 "hello-world.sh") in new stack ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Asterisk: The Definitive Guide, 3rd Edition

Asterisk: The Definitive Guide, 3rd Edition

Leif Madsen, Jim Van Meggelen, Russell Bryant
Asterisk: The Future of Telephony, 2nd Edition

Asterisk: The Future of Telephony, 2nd Edition

Jim Van Meggelen, Jared Smith, Leif Madsen
Asterisk: The Definitive Guide, 5th Edition

Asterisk: The Definitive Guide, 5th Edition

Jim Van Meggelen, Russell Bryant, Leif Madsen

Publisher Resources

ISBN: 9781449332433Errata Page