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, “A sample AGI script, hello-world.sh”.

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
    -- Launched AGI Script /var/lib/asterisk/agi-bin/hello-world.sh
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_request: hello-world.sh
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_channel: SIP/0004F2060EB4-00000009
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_language: en
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_type: SIP
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_uniqueid: 1284382003.9
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_version: 1.8.0-beta4
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_callerid: 2563619899
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_calleridname: Russell Bryant
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_callingpres: 0
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_callingani2: 0
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_callington: 0
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_callingtns: 0
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_dnid: 7010
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_rdnis: unknown
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_context: phones
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_extension: 500
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_priority: 1
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_enhanced: 0.0
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_accountcode: 
<SIP/0004F2060EB4-00000009>AGI Tx >> agi_threadid: 140071216785168
<SIP/0004F2060EB4-00000009>AGI Tx >> 
<SIP/0004F2060EB4-00000009>AGI Rx << ANSWER
<SIP/0004F2060EB4-00000009>AGI Tx >> 200 result=0
<SIP/0004F2060EB4-00000009>AGI Rx << SAY ALPHA "Hello World" ""
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/h.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/e.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/l.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/l.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/o.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/space.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/w.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/o.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/r.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/l.gsm' (language 'en')
    -- <SIP/0004F2060EB4-00000009> Playing 'letters/d.gsm' (language 'en')
<SIP/0004F2060EB4-00000009>AGI Tx >> 200 result=0
    -- <SIP/0004F2060EB4-00000009>AGI Script hello-world.sh completed, returning 0