[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 ...


#!/usr/bin/perl
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 =
DBI->connect("dbi:mysql:$MYSQL{database}:$MYSQL{hostname}","$MYSQL{username}","$MYSQL{password}")||
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.");
$AGI->verbose("$str");
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"."@"."209.9.9.34";
$AGI->set_callerid(7347777777);

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

else

{
$AGI->verbose("$userid is not online.");
#$AGI->stream_file('custom/myrecording');
$AGI->stream_file('followme/sorry');
$AGI->stream_file('en/vm-nobodyavail');
}

$AGI->hangup();


Thanks everyone for all the help.
Ed
-------------- 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