Category Archives: AGI

PHPAGI2


[root@alfamart agi-bin]# vim /etc/asterisk/manager.conf

[mosesagi]
secret = mosesagi
read = all
write = all

[root@alfamart agi-bin]# vim /etc/asterisk/extensions.conf

[ecentrix-agents]
exten => _9XXXX,1,Dial(SIP/${EXTEN:1},,tT)
exten => _9XXXX,n,Noop(${CHANNEL})
exten => _9XXXX,n,Softhangup(${CHANNEL})

#!/usr/bin/php -q
<?php
set_time_limit(30);
require_once(“include/phpagi-asmanager.php”);
//$asm = new AGI_AsteriskManager();
$asm = new AGI_AsteriskManager(“/etc/asterisk/phpagi.conf”,””);
$asm->connect(“localhost”,”mosesagi”,”mosesagi”);
$asm->send_request(‘Originate’, array(‘Channel’=> “SIP/8801”, ‘Context’ => “ecentrix-agents”, ‘Priority’ => 1, ‘Async’ => true,’callerid’=>”8801″,’Exten’=>98802,’Callerid’=>8801));
$asm->disconnect();
?>

[root@alfamart agi-bin]# pwd originate.php
/var/lib/asterisk/agi-bin

[root@alfamart agi-bin]# php originate.php => DIAL 8801 then DIAL 8802

 

Advertisements

PHPAGI + HANDLE MULTIPLE DID NUMBER


extensions.conf

[ecentrix-agents]
exten => 3000,1,Ringing
exten => 3000,n,Answer
exten => 3000,n,AGI(inbound_flow_agi.php)

#!/usr/bin/php -q
<?php
/*simple ivr phpagi
by moses
*/
set_time_limit(0);
ob_implicit_flush(false);
require(‘include/phpagi.php’);
$agi = new AGI();

/*connection mysql*/
if (!$dbh = mysql_connect(‘localhost’, ‘root’, ‘root’)) {
$agi->verbose(‘mysql_connect() failed, exiting…’);
$agi->hangup();
exit;
}
mysql_select_db(‘voip’, $dbh);
$agi->verbose(‘mysql_connect() connected…’);
/*end connection mysql*/

$query = “SELECT * FROM acd WHERE number='{$agi->request[‘agi_callerid’]}'”;

if (!$res = mysql_query($query, $dbh)) {
$agi->verbose(‘mysql_query() failed: ‘ . mysql_error());
$agi->hangup();
exit;
}

if (mysql_num_rows($res) == 0) {
$agi->verbose(‘mysql_num_rows() returned zero’);
// $agi->stream_file(‘wrong_inbound_number’, ‘#’);
$agi->hangup();
exit;
}

$data = mysql_fetch_array($res);

$agi->verbose(“number : {$data[‘number’]} extension : {$data[‘extensions’]} type : {$data[‘type’]}”);

mysql_free_result($res);

//$agi->stream_file(‘igc_001′);
$ext_destination=””;
$loop=0;
while($ext_destination == “”){
//$result = $agi->fastpass_get_data($buffer,’igc_002′, 3000, 4);
$result = $agi->fastpass_get_data($buffer,’igc_002’, 5000, 4);
$ext_destination=$result[‘result’];
$loop++;
if($loop>2){
$agi->hangup();
$loop=0;
break;
}
}

$agi->verbose($agi->request[“agi_callerid”]);
//operator
if($ext_destination==0){
if ($data[‘type’] == ‘seq’) {
// Dial sequentially
$exts = split(‘,’, $data[‘extensions’]);
foreach ($exts as $ext) {
$agi->exec(‘Dial’, ‘SIP/’ . $ext . ‘,15’);
}
}else if ($data[‘type’] == ‘sim’) {
// Dial simultaneously
$exts = split(‘,’, $data[‘extensions’]);

$last = count($exts);
$i = 1;
// Build dial string
foreach ($exts as $ext) {
$args .= ‘SIP/’ . $ext;
if ($i != $last) {
$args .= ‘&’;
}
$i++;
}
$agi->exec(‘Dial’, $args . ‘,60′,’tT’);

}
}else{
//dial extension
$agi->exec(‘Dial’,’SIP/’ .$ext_destination. ‘,60′,’tT’);
$agi->verbose($agi->channel_status($agi->agi_channel));
}
mysql_close($dbh);
$agi->hangup();
?>

 

 

shisdew

Listens until think alike

moses.spaceku@yahoo.com / voip ipbx

Hosted PBX, IP-PBX SOHO/ CALL CENTER, VOICE GATEWAY, VOICE CARD, COST EFECTIVE SOLUTIONS (LCR), GSM/CDMA GATEWAY

%d bloggers like this: