Feb 18 2008

How To pass argument to Asterisk Dialplan with PHP-AGI!!!

Category: AsteriskBipin Balakrishnan @ 3:24 pm

It is some times necessary to pass a argument to asterisk dialplan and read that variable or value
from another script.In PHP-AGI this thing is done as follows
Passing an argument or variable value is setting it in the “orginate application”.

eg:
<?php
require(’phpagi/phpagi.php’);
require_once(’phpagi/phpagi-asmanager.php’);
$number = ‘9946236111′;
$asm = new AGI_AsteriskManager();
if($asm->connect())
{
$call = $asm->send_request(’Originate’,
array(’Channel’=>”SS7/9946236329″,
‘Context’=>’demospeech’,
‘Priority’=>1,
‘Callerid’=>$number,
‘Async’=>’true’,
‘Variable’=>’cnum=9947000XXX′)); //asterisk variable setting as “9947000XXX″
$asm->disconnect();
}
?>

The “cunum variable is accepted in asterisk as

[demospeech]
exten => s,1,AGI(incoming.php|${CNUM}) //here “{CNUM}” will store the variable value.

To get that value in another script is done by as follows

#!/usr/bin/php -q
<?php
set_time_limit(0);
require(’phpagi/phpagi.php’);
$agi = new AGI();
$agi->answer();
$cid = $argv[1]; // ” $argv[1]” contain the asterisk variable value..here the value is 994000XXX                                                                                                             $agi->verbose($cid); //This will print “9947000XXX″
?>

syntax: For Coping file from a remote system

rsync [OPTIONS]..SRC [SRC]… [USER@]HOST:DEST

example:

rsync -azvc –rsh=’ssh -p22′ root@213.124.200.38:/etc/zaptel.conf /home/bipin/asterisk_ss7/

will copy the file “zaptel.conf” to the local system with path /home/bipin/asterisk_ss7/