A quick introduction to the Open Source Asterisk PBX and the by gregoria

VIEWS: 224 PAGES: 26

									Asterisk and AGI
A quick introduction to the Open Source
Asterisk PBX and the Asterisk Gateway Interface


Nick Barendt (not an expert)   nickbarendt@bitbacker.com
Asterisk - Open Source PBX
http://www.asterisk.org
Private Branch Exchange - Private Phone System
Open Source - GPL
Digium - developer (also supplies telephone hardware)
Mark Spencer (also Gaim)
Platforms - Linux, OSX, Windows, probably others
                                        x123
                                         x123
                           FXO/FXS        x123
                                           x123
                                            x123
                                             x123


     PSTN            PBX
                                     xBob
                                      xBob
                                       xBob
                                        xBob
                            VoIP         xBob
                                          xBob
                                           xBob




What is a PBX?
Connects a private telephone system to world-
wide Public Switched Telephone Network
PBX Functionality
 Extensions (x100, x101, x102,...)
 Call groups
 Call hunting
 Voicemail
 Conferencing
 IVR - hateful, hateful things
Asterisk Channels
Channels are phone connections
Traditional POTS hardware
  Foreign eXchange Office (FXO) - normal phone
  Foreign eXchange Station (FXS) - telco
VoIP - SIP, IAX, etc.
Each channel type has a configuration file (e.g., /etc/
asterisk/sip.conf)
Asterisk Dialplan
 Dialplan is the heart of the Asterisk PBX functionality
 Consists of:
   Contexts
   Extensions
   Priorities
   Applications
Asterisk Dialplan (cont.)
 Contexts
   named groups of extensions
   provide scoping and control
 Extensions
   phone numbers supported within the context
   drive traversal of dialplan, along with priorities and
   applications
Asterisk Dialplan (cont.)
 Format of an extension:
 exten => name, priority, application()
 name - alphanumeric name for extension
 priority - ordinal for extension instruction
 application - application to execute
Asterisk Dialplan (cont.)
 call for bob comes in...
 Execution:
 exten => bob, 1, application()
 exten => bob, 2, application()
 exten => bob, 3, application()
 exten => bob, 4, application
Very Basic Dialplan
 [internal]                               Context is ‘internal’
 exten => 100,1,Answer()                  1: answer extension 100
 exten => 100,2,Wait(1)
                                          2: wait 1 second
 exten => 100,3,Playback(‘hello-world’)

 exten => 100,4,Hangup()                  3: play audio file
                                          4: hangup
Dialplan Demo 1
Demo Setup

Macbook Pro (OSX) with X-Lite softphone application
Parallels Virtualization Software
Ubuntu (Edgy) VM with Asterisk Installed
Virtual Network connecting VM and OSX
Dial() Application
 [internal]                      Context is ‘internal’
 exten => 200,1,Answer()         1: answer extension 100
 exten => 200,2,Dial(SIP/nick)
                                 2: dial SIP channel 100
 exten => 200,3,Hangup()
                                 3: hangup
Dialplan Demo 2
Dialplan Notes
Outgoing calls are just another extension
Many additional applications:
  Goto, GotoIf, Congestion, DBput, DBget, etc.
Macros, Variables, Conditionals, Pattern matching
Voicemail
Various GUI Web interfaces available
Asterisk Gateway Interface
 Asterisk Gateway Interface (AGI)
   write custom dialplan aplications
   akin to CGI - application gets stdin, stdout, stderr
 EAGI - like AGI, but get access to audio stream
 DeadAGI - like AGI, but works on dead channels
 FastAGI - call AGI applications across network
AGI Operation (cont.)

 AGI Applications can:
   Play audio files and do voice menu prompts
   Transfer current call to other portions of Dialplan
   Access databases
   Arbitrarily complex logic
AGI Operation
AGI application is called from dialplan like:
  exten => 100, 5, AGI(agiscript)
AGI scripts normally live somewhere like:
  /usr/share/asterisk/bin-agi/
Asterisk and AGI script communicate through stdin,
stderr, stdout
AGI Operation (cont.)
 Asterisk sends key:value pairs on AGI application stdin
 at startup, followed by a blank line:

agi_request: sample.py
agi_channel: SIP/nick
agi_callerid: 12345
agi_extension: 123
agi_priority: 5
agi_context: internal
AGI Operation (cont.)
 Asterisk and AGI application continue to send
 commands and responses to each other through stdin
 and stdout
 For instance, AGI application could play an audio file
 named ‘beep’, returning if a DTMF 1 is pressed:
 print ‘STREAM FILE beep “1“ \n’
 Asterisk will return 0 on stdin if no digit pressed, the
 digit value, or -1 if the call hangs up
AGI Operation (cont.)


 AGI execution consists of AGI application sending
 commands to Asterisk, receiving results, making
 decisions, repeat....
 Until done - call may be hung up, transferred, etc.
Python and AGI

pyst - AGI Library
  simplifies writing AGI applications
  includes module for Asterisk Manager (send
  commands and observe events over TCP/IP)
  includes module to work with Asterisk configuration
  files
pyst AGI class

 pyst AGI class
   handles environment variables on startup
   handles basic asterisk functions (streaming files,
   saying digits, querying users for DTMF, asterisk
   database, record, etc.)
   simplifies interaction with Asterisk (manages stdin/
   stdout)
AGI Demo
Asterisk and AGI

Lots of capabilities
Text-to-Speech via Festival
Remote control and monitoring
Conferencing
Messaging
Further Info

 http://www.asterisk.org
 http://www.voip-info.org
 http://www.digium.com/
 Asterisk: The Future of Telephony - O’Reilly (FREE)

								
To top