Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

miércoles, 18 de abril de 2012

Asterisk AGI para Asignar el nombre desde una base de datos mysql

Asterisk simple php lookup mysql database to set callerid name

This script use the AGI to lookup a telephone number in a mysql database created by the user to set the name of the caller

Requires phpagi (phpagi-asmanager.php phpagi-fastagi.php phpagi.php in script folder), php and mysql


exten => 100,1,AGI,/path/to/php/script/lookup
exten => 100,n,Set(CALLERID(name)=${lookupcid})
exten => 100,n,Dial(SIP/203,20,t)
exten => 100,n,Hangup

lookup script:

#!/usr/bin/php -q
require 'phpagi.php';
$agi = new AGI();

$no=preg_replace("#[^0-9]#","",$agi->request[agi_callerid]);//remove any non numeric characters

connect to "asterisk" database in mysql; in this case only 1 table "clients"
column telsearch contains concatenated mobile, home and work numbers
e.g. 0121777887207986238123
script will search for caller number within this field
$db = 'asterisk';
$dbuser = 'xxx';
$dbpass = 'xxx';
$dbhost = 'localhost';

mysql_select_db("$db"); //or die("could not open database");
$row=mysql_query("select title,firstname,lastname from clients where telsearch like '%$no%' LIMIT 1");
if (mysql_num_rows($row)==1&&strlen($no)>4){//if found number and number greater than 4 digits to avoid 3 digit internal extensions
        if ($row[title]) $name .= $row[title]." ";
        if ($row[firstname]) $name .= $row[firstname]." ";
        if ($row[lastname]) $name .= $row[lastname];
else $name=$agi->request[agi_callerid];//else set calleridname to callerid number
$agi->set_variable("lookupcid", $name);

No hay comentarios:

Publicar un comentario