Call automation with Asterisk and Issabel PBX

Open source communication systems based on Asterisk, such as Issabel PBX, Elastix or FreePBX, allow call automation, to interact with users, and additionally receive or send information from other platforms.

Call automation with Asterisk
Call automation with Asterisk


Now we will detail about Asterisk’s options for call automation:


1. Asterisk’s Dialplan

The dialplan is a script specific to Asterisk, which controls the sequence of a call, and therefore the different decisions that can be made, according to the responses of the user, or another system integrated to it.

Depending on the Asterisk distribution, some are automatically created or modified by Issabel (extensions.conf and extensions_additional.conf), and there is another one that can be modified manually by the user (extensions_custom.conf).

In general, a dialplan is headed by a context, which is named between the symbols []. Below the context there are the different lines of the dialplan, conformed as follows:

[context]
exten => extension, priority, Command(parameters)

Where the extension indicates the number that a user dials, or a number that enters through a trunk; the priority shows the sequence of execution of the commands, and the Command is the application that you want to execute.

For example the line:

exten => 123,1,SayDigits(485)

Instructs asterisk so that when the user dials 123 or the number 123 is received on the trunk, it first executes the action: read the digits 485.


2. AGI – Asterisk Gateway Interface

AGI is a function that allows the execution of PHP, Perl or Phyton scripts external to Asterisk, exchanging information between Asterisk and other systems or databases. The AGI application allows parameters to be sent to the script to be its input data. The script returns data to Asterisk by means of variables that are loaded through an AGI object.

The script file must be located in the /var/lib/asterisk/asterisk/agi-bin directory, with execution permissions. This file must contain a structure as shown:

!/usr/bin/php -q

<?php 

require("/var/lib/asterisk/agi-bin/phpagi.php");

//Get parameters from asterisk

$p1 = $arg[1];

// Execute code from PHP 

...

// Return values to asterisk 

$agi = new AGI();
$agi->answer();
$agi->set_variable('exit',$exit);

?>

The variables returned to asterisk through the agi object are accessible through the ${var} format.

For example, if we have a php script called action.php, it can be called from the dialplan as follows:

exten => 123,1,ExecIf($["${follow}"="1" ]?AGI(action.php,${p1},{p2}))

In this example, the script action.php is executed with the parameters p1 and p2, when the continuous variable has a value equal to 1.

However, the AGI object can also perform the whole dialplan sequence from the script itself, by means of commands that execute from the script to the asterisk, for example:

// Get caller ID
$cid = $agi->parse_callerid();

// Sounds text to audio
$agi->text2wav("Hi, good morning");

// Hang up the call
$agi-> hangup();

In this way, the entire logical sequence of the call is controlled from the script, with the facilities and functions that the supported programming languages contain.


3. Access to MySQL from the dialplan

From the dialplan it is possible to connect to a local or external database, through the MySQL application, integrating the results of the queries to dialplan variables, or executing other actions in the database such as inserting, updating or deleting data.

The use of this function is performed as follows:

; Connection to database, with a valid username and password 
exten => _X.,n,MYSQL(Connect connid ${serverdb} ${userdb} ${passdb} ${dbname})

; Execute query MySQL
exten => _X.,n,MYSQL(Query r1 ${connid} SELECT p1, p2 FROM tabla where p2='${EXTEN}')

; The results of the query are assigned to Asterisk variables.
exten => _X.,n,MYSQL(Fetch fetchid ${r1} p1 p2)

; The query is free
exten => _X.,n,MYSQL(Clear ${r1})

; Disconnect database
exten => _X.,n,MYSQL(Disconnect ${connid})

4. AMI – Asterisk Manager Interface

This is a way to integrate Asterisk with external applications, through a TCP/IP type interface, based on key : value queries.

In this way you can send commands to Asterisk, receive their response and also receive events when they occur.

AMI is enabled in Asterisk in the manager.conf file. In this file are the login credentials and the IP addresses with permission or denial to execute commands.

For example, once the TCP connection to Asterisk is established, commands can be sent such as:

Action: Login
ActionID: 1
Username: administrator
Secret: password1

Receiving a reply from Asterisk as:

Response: Success
ActionID: 1
Message: Authentication accepted


Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.