PhpAgi, DialStatus Script

865 views
Skip to first unread message

Raúl García

unread,
May 18, 2012, 11:03:17 AM5/18/12
to asterisk-es
Buenos dias.

Tengo la siguiente consulta.
tengo este Escenario

exten => X.1,AGI(randon.agi,${EXTEN})
exten => h,1,AGI(HangUp.agi,${CDR(start)},${CDR(clid)},${CDR(src)},$
{CDR(dst)},${CDR(channel)},${CDR(dstchannel)},${CDR(lastapp)},$
{CDR(lastdata)},${CDR(duration)},${CDR(billsec)},${CDR(disposition)},$
{code})


#######################randon.agi####################3
#!/usr/bin/php
<?php

$argv[1];
$callNum=$argv[1];
//include("conex.php");
require ("/var/lib/asterisk/agi-bin/phpagi-2.20/phpagi.php");

set_time_limit(30);
error_reporting(E_ALL);
$in = fopen("php://stdin","r");
$stdlog = fopen("/var/log/asterisk/agi.log", "w");
header("Content-Type: text/html;charset=utf-8");
$agi= new AGI();
$c=0;


$hostname_call = "localhost";
$database_call = "asterisk";
$username_call = "asterisk";
$password_call = "passasterisk";
$yacall = mysql_connect($hostname_call, $username_call,
$password_call) or trigger_error(mysql_error(),E_USER_ERROR);

do
{

mysql_select_db($database_call, $call);
$query_e="select * from call where Status='Libre' order by RAND()
limit 0,1";
$result=mysql_query($query_e);
$row_e = mysql_fetch_assoc($result);
$channels=$row_e['Channels'];

//$agi->NoOp($channels);
$mysqldate = date('Y-m-d H:i:s');

$id=$row_e['id'];
$hora=date('H:i:s');
$agi->set_variable("code",$id);
//$agi->set_variable("channel",$channels);
mysql_query("UPDATE jumpyacall SET
Fecha='$mysqldate',Status='Conectado' where id='$id'");
//$channels='p25';

$agi-> exec('DIAL',"SIP/$channels/$callNum");
$var=$agi->get_variable('DIALSTATUS');
$Ver="${var['data']}";
$agi->NoOp($Ver);
//sleep(1);
if($Ver=='CHANUNAVAIL' or $Ver=='CONGESTION' or $Ver=='FAILED'){
mysql_query("update call set Disposicion='$Ver',Status='Stop' where
id='$id'");
}

//sleep(1);
$c++;
}while($Ver=='BUSY' and $c<='26' or $Ver=='CHANUNAVAIL' and $c<='26'
or $Ver=='CONGESTION' and $c<='26' or $Ver=='FAILED' and $c<='26');
//$agi-> set__variable("disposicion",$Ver);
//mysql_query("UPDATE jumpyacall set Status='Libre',EstatusCall='$Ver'
where id='$id'");

?>
el randon.agi lo que haces es que busca un canal disponible por donde
enviar las llamadas en base a la consulta $query_e.
el hangup.agi me esta funcionando bien.
Cual es el problema? que no puedo setear los diferente estatus, tales
como, answer, ringing, congestion, no answer desde el mismo script,
debido a que el Scritp se para en este parametro $agi->
exec('DIAL',"SIP/$channels/$callNum"); si la llamada es cerrado y el
script no se completa no sigue mas corriendo los otros parametros
definidos.

lo trate de poner en el constesto h, pero me esta dando el status No
Answer debido a que lo ve como un canal muerto.

Quiero saber si alguien a tenido este inconveniente y como lo ha
resuelto.
Reply all
Reply to author
Forward
0 new messages