Introducción a Asterisk AGI AGI (Asterisk Gateway Interface) ●
●
Interfaz para que nuestros programas puedan comunicarse con Asterisk. AGI es parecido a CGI: ●
●
●
La comunicación de AGI con Asterisk es vía stdin/stdout.
AGI, EAGI (audio), FastAGI (remoto), DeadAGI. Los scripts AGI pueden ser escritos en cualquier lenguaje. (Perl, Python, PHP, C, ... )
3 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Introducción a Asterisk AGI Asterisk PBX
Asterisk Switching Core
l e n n a e h c a C f r k e t s i n r I e t s A
TDM E1 ANALOG SIP IAX2 MGCP
Asterisk AGI Module
STDIN/STDOUT Database AGI Script
WWW Coffee Maker
4 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Introducción a Asterisk AGI Comunicación AGI <--> Asterisk ●
●
●
STDOUT – Para enviar algo a Asterisk el script AGI escribe algo en stdout. STDIN – Para recibir información de Asterisk el script AGI usa el stdin.
STDERR – Para escribir información de DEBUG en el CLI el script usa stderr. 5 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Introducción a Asterisk AGI Scripts AGI ●
Directorio por defecto: Nota: Podemos guardarlos donde queramos, pero deberemos indicar la ruta completa.
●
Debe de ser ejecutable:
6 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Introducción a Asterisk AGI ●
Invocarla desde el dialplan:
●
Paso de parámetros
●
Deben existir en la extensión actual: – – –
Variables dadas por el entorno Asterisk Definidas por nosotros mismos 7 ... Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Comandos en AGI answer channel status database del database deltree
Answer channel Returns status of the connected channel Removes database key/value Removes database keytree/value
database get
Gets database value
database put
Adds/updates database value
exec
Executes a given Application
get data get full variable get variable get option hangup noop
Prompts for DTMF on a channel Evaluates a channel expression Gets a channel variable Stream file, prompt for DTMF, with timeout Hangup the current channel Does nothing
receive char
Receives one character from channels supporting it
receive text
Receives text from channels supporting it
record file
Records to a given file
say alpha
Says a given character string
say digits
Says a given digittring
say number
Says a given number
8 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Comandos en AGI say phonetic
Says a given character string with phonetics
say date
Says a given date
say time
Says a given time
say datetime send image send text set autohangup
Says a given time as specfied by the format given Sends images to channels supporting it Sends text to channels supporting it Autohangup channel in some time
set callerid
Sets callerid for the current channel
set context
Sets channel context
set extension set music
Changes channel extension Enable/Disable Music on hold generator
set priority
Set channel dialplan priority
set variable
Sets a channel variable
stream files
ends audio file on channel
control stream file tdd mode verbose wait for digit
Sends audio file on channel and allows the listner to control the stream Toggles TDD mode (for the deaf) Logs a message to the asterisk verbose log Waits for a digit to be pressed
9 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Primer script AGI Un ejemplo: ●
script (ejemplo.php) :
●
Dialplan ( extensions.conf ) :
10 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Primer script AGI ●
Cabeceras:
11 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
PHPAGI ¿Para qué? ●
Se encarga de las cabeceras
●
Posee la mayoría de los comandos AGI
●
Posee “wrappers” para las funciones text2wave => festival Nota: Instalar festival en castellano. ●
Cuando un método es invocado el resultado se guarda en un array de variables. Depende del método a veces el resultado esta en la posición indicada por 'result' o por 'key'.
NOTA: Consultar siempre el c ódigo fuente de phpagi.php para conocer el comando (o la ayuda generada). http://phpagi.sourceforge.net/phpagi2/docs/
17 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
PHPAGI – Asterisk Manager Asterisk Manager ●
●
El asterisk Manager Interface es un servidor TCP, capaz de comunicarse con Asterisk, haciendo posible que aplicaciones remotas envíen comandos a Asterisk
PHPAGI incluye una librería capaz de manejar este sistema “phpagi_AsteriskManager”
18
Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
PHPAGI – Asterisk Manager Asterisk Manager (II) ●
●
Configurar en phpagi.conf
Y en nuestro script:
19 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Consejos ●
Consejos: – No hay que hacer todo con AGI, el dialplan sigue estando ahí :) –
Usa en la medida de lo posible las variables del canal.
–
Hacer los scripts AGI modulares.
–
Si el AGI crece demasiado --> refactoring 20 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Referencias Bibliografía ●
Asterisk, The Future of Telephony. Jim Van Meggelen, Jared Smith & Leif Madsen – O' Reilly
Sitios Web ●
●
Voip-info: http://www.voip-info.org Web PHPAGI: http://phpagi.sourceforge.net/
21 Gorka Gorrotxategi – David Santamaría
CURSO ASTERISK AGI y PHPAGI – Modulo 2
Licencia
●
Detalles de la licencia – http://creativecommons.org/licenses/by/2.5/es/de ed.es 22 Gorka Gorrotxategi – David Santamaría