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

Asterisk: The Definitive Guide, 5th Edition

by Jim Van Meggelen, Russell Bryant, Leif Madsen
June 2019
Intermediate to advanced content levelIntermediate to advanced
412 pages
11h 4m
English
O'Reilly Media, Inc.
Book available
Content preview from Asterisk: The Definitive Guide, 5th Edition

Chapter 18. Asterisk Gateway Interface

Caffeine. The gateway drug.

Eddie Vedder

The Asterisk dialplan has evolved into a simple yet powerful programming interface for call handling. Many people, however, especially those with a programming background, prefer to implement call handling in a traditional programming language. The Asterisk Gateway Interface (AGI) allows for the development of first-party call control in the programming language of your choice.

Quick Start

This section gives a quick example of using the AGI.

First, let’s create the script that we’re going to run. AGI scripts are usually placed in /var/lib/asterisk/agi-bin.

$ cd /var/lib/asterisk/agi-bin

$ vim 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

$ chown asterisk:asterisk hello-world.sh

$ chmod 700 hello-world.sh

Now, add the following line to /etc/asterisk/extensions.conf, in your [sets] context:

exten => 237,1,AGI(hello-world.sh)

Save and reload your dialplan, and when you call extension 237 you should hear Allison spell out “Hello World.”

AGI Variants

There are a few variants of AGI that differ primarily in the method used to communicate with Asterisk. It is good to be aware of all the options so you can make the best choice based on the needs of your application.

Process-Based AGI

Process-based AGI is the simplest variant ...

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

The Linux Command Line, 2nd Edition

The Linux Command Line, 2nd Edition

William E. Shotts

Publisher Resources

ISBN: 9781492031598Errata PageSupplemental Content