Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

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


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users
View previous topic :: View next topic  
Author Message
q.edward at gmail.com
Guest





PostPosted: Fri May 01, 2009 7:28 pm    Post subject: [Freeswitch-users] Asterisk AGI.PL Total Noob HELP plz... Reply with quote

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
Back to top
diego.viola at gmail.com
Guest





PostPosted: Sat May 02, 2009 8:23 am    Post subject: [Freeswitch-users] Asterisk AGI.PL Total Noob HELP plz... Reply with quote

Hi Edward,

You could use perl from the dialplan or use the Event socket, or ESL,
I use the event socket with a ruby library called freeswitcher and it
works really well.

Just take a look at the wiki (http://wiki.freeswitch.org/) for more
info and/or ask us for help at #freeswitch @irc.freenode.net.

Hope that gives some idea to you.

Regards,

Diego

On Fri, May 1, 2009 at 8:26 PM, Edward Q. <q.edward@gmail.com> wrote:
Quote:
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

_______________________________________________
Freeswitch-users mailing list
Freeswitch-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org



_______________________________________________
Freeswitch-users mailing list
Freeswitch-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services