[Asterisk-Users] How to get the Called id with AGI

Karl Dyson kd at junesta.com
Fri Jun 11 00:58:30 MST 2004


Hi,

I lookup incoming calls in a MySQL DB to try and match up names and
display them with the number on the 7905s. Inbound pstn calls land based
on dring settings, so I pass (in this case 918) to be added to the
display name to indicate which of my inbound numbers was dialled. So, on
the 7905 I get

918:Callers Name
01234567890

Or,

918:Unknown
01234567890

....if I don't recognise the number.

Hope this helps,

Karl

### extensions.conf ###

[inbound-pstn-1]
exten => s/,1,NoOp(${EXTEN})
exten => s/,2,Goto(inbound-pstn-nocli,s,1)

exten => s,1,NoOp(DRING:918)
exten => s,2,AGI(clilookup.pl,918)
exten => s,3,Goto(inbound-pstn,s,3)

exten => t,1,Hangup

exten => h,1,Hangup

### clilookup.pl ###

#!/usr/bin/perl
#

my $debug = 1;

use Asterisk::AGI;
use DBI;

$AGI = new Asterisk::AGI;

my $dsn = 'dbi:mysql:database=asterisk;host=<snip>';
my $dbuser = '<snip>';
my $dbpass = '<snip>';

my $dbh = DBI->connect($dsn, $dbuser, $dbpass,{ PrintError => 0,
RaiseError => 0, AutoCommit => 0 });

my %input = $AGI->ReadParse();

foreach $thing (sort keys %input) {
       $res = $input{$thing};
       $AGI->verbose("input{$thing} = $res",1) if $debug;
}

my $id = shift;
$id .= ":" if $id;
$AGI->verbose("id = $id",1) if $debug;

$cli = $input{"callerid"};
my $qcli = $dbh->quote($cli);

my $sth = $dbh->prepare(qq{select name from numbers where number=$qcli})
|| die;

$sth->execute || die;

my $cliname;
if($sth->rows > 0)
{
  $cliname = $sth->fetchrow_array;
}
else
{
  $cliname = "Unknown";
}
$sth->finish;

$AGI->set_callerid("\"${id}${cliname}\"<$cli>");

$dbh->disconnect;
exit 0;

> -----Original Message-----
> From: asterisk-users-admin at lists.digium.com [mailto:asterisk-users-
> admin at lists.digium.com] On Behalf Of usedcanon
> Sent: 10 June 2004 23:33
> To: asterisk-users at lists.digium.com
> Subject: RE: [Asterisk-Users] How to get the Called id with AGI
> 
> Hi Angel,
> 
> I assume you mean CALLERIDNUM (the number part of caller ID),
> 
> The easiest thing in that case is to pass it as a parameter to your
AGI
> script
> 
>   extex => 500,1,AGI(myscript.py|${CALLERIDNUM})
> 
> in your script you just used the argument passed as usual ( I am not a
> perl expert, so not sure on the syntax there )
> 
> Hope this helps.
> 
> Umar.
> 
> 	-----Original Message-----
> 	From: asterisk-users-admin at lists.digium.com
[mailto:asterisk-users-
> admin at lists.digium.com]On Behalf Of Angel Diaz
> 	Sent: 10 June 2004 22:41
> 	To: asterisk-users at lists.digium.com
> 	Subject: [Asterisk-Users] How to get the Called id with AGI
> 
> 
> 	Hi all,
> 	    Is there a way to get the "called id" (the B number) with
AGI
> perl ?
> 	I know how to get the caller id which is working fine and is
just
> below:
> 	#!/usr/bin/perl
> 
> 	use Asterisk::AGI;
> 
> 	$AGI = new Asterisk::AGI;
> 
> 	my %input = $AGI->ReadParse();
> 
> 	$callerid = $input{'callerid'};
> 
> 	$AGI->say_digits($callerid);
> 
> 	}
> 
> 	Thanks in advance,
> 
> 	Angel.
> 
> 
> ________________________________
> 
> 	Do you Yahoo!?
> 	Friends. Fun. Try the all-new Yahoo! Messenger
> <http://messenger.yahoo.com/>
> 
> 
>
________________________________________________________________________
> This e-mail has been scanned for all viruses by Star Internet. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk <http://www.star.net.uk>
>
________________________________________________________________________



________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the asterisk-users mailing list