Calling external script from Asterisk dial plan using AGI
Visual Dialplan supports AGI (Asterisk Gateway Interface) that can be used to call external scripts from the dial plan.
The Asterisk Gateway Interface is an interface for adding functionality to dial plan with many different programming languages. Perl, PHP, C, Pascal, Bourne Shell – it’s your choice.
The only requirements are:
* AGI script must be executable
* AGI script must be located in /var/lib/asterisk/agi-bin folder
How to use AGI?
AGI building block is located at the ‘Exe’ sheet.
Simply place the AGI building block on the working area and fill in the AGI block properties.
For example, on the picture below we instructed AGI to call ‘hello_world.php’ PHP script. We use ‘Simple AGI’ type and we didn’t pass input parameters because this script does not expect it.
This is simple example of an AGI call.
For more complex AGI calls check the AGI help page in the Visual Dialplan documentation.
Hello World example
You will need the ‘hello_world.php’ AGI script uploaded to your Asterisk server in order to execute the above AGI call.
Here is the simple PHP script that will play the ‘tt-monkeys’ file from /var/lib/asterisk/sounds.
Simply create ‘hello_world.php’ file in your /var/lib/asterisk/agi-bin folder with the following content and call the script using AGI block from Visual Dialplan.
#!/usr/local/bin/php -q
<?php
set_time_limit(0);
require(‘phpagi.php’);
$agi = new AGI();
$agi->answer();
// Play the tt-monkeys file from /var/lib/asterisk/sounds
$agi->stream_file(‘tt-monkeys’);
$agi->hangup();
?>