[Freeswitch-users] Asterisk AGI.PL Total Noob HELP plz...

Edward Q. q.edward at gmail.com
Fri May 1 17:26:53 PDT 2009

Hi guys ..

I am a total noob on all this FS and asterisk thing ..
I have a system already running on Asterisk and i want to migrate it to FS
I have an AGI made in perl that runs everytime and i need to be at least
pointed out on how i can approach on transferring this to FS

Here is the AGI .. its simple ...

use Asterisk::AGI;
use DBI;
use strict;

my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
$input{'callerid'} =~ /(^.+<(\d+)>$)|((^\d+$))/;
$input{'calleridani'} = $2 || $3;
#my $userid = $input{'calleridani'};
my $userid=$input{'extension'};
#my $userid='1001';
# Config options
my %MYSQL = (
    hostname    =>    "localhost",
    username    =>    "callmeuser",
    password    =>    "mycallmepass",
    database    =>    "executives"

my $dbh =
die("Couldn't connect to database!\n");
$AGI->verbose("Connected to database.");
$AGI->verbose("Call for : $userid");

 print STDERR "$userid";
 print STDERR "hello testing db connected";
my $debug=2;
my $phone="";
#debug("Connect to database");
#debug("Transferred call, using original cid: $name",5);
my $str ="select phone from timetable where exten='$userid' and online='Y'
$AGI->verbose("Checking if $userid is online right now and get his phone
number from db.");
print STDERR "$str";
my $sth =$dbh->prepare($str);
$sth->execute || die("Couldn't exec sth2!");
#my $pin = $sth->fetchrow_hashref;
#print STDERR "xxxx";
#print STDERR "$pin";

while (my @row = $sth->fetchrow_array)
$phone = $row[0];
print STDERR "xxxx";
print STDERR "$phone";
print STDERR "vvvvx";
$AGI->verbose("$userid is online and his phone number is $phone");
#$AGI->exec('DIAL', "SIP/$phone");
if  ($phone!="")

$AGI->verbose("Calling  $userid at $phone");
my $dialstr="SIP/$phone"."@"."";

$AGI->exec('DIAL', $dialstr);
my $st=$AGI->get_full_variable('status',$dialstr);
$AGI->verbose("channel status is : $st");


$AGI->verbose("$userid is not online.");


Thanks everyone for all the help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20090501/ea1dc439/attachment-0002.html 

More information about the FreeSWITCH-users mailing list