[asterisk-users] Get dialed numbers in AGI
Doug Crompton
doug at crompton.com
Thu Jan 11 10:20:15 MST 2007
I am not sure if this is what you meant in your query. Here is a Perl
script that checks a dialed numbers areacode/exchange and determines if it
is a local or long distance call. I then send it out either PSTN or SIP.
The dialed number is sent to the script which returns true or false.
There might be a better way to check the return code but I was never able
to get a straight answer on that and this works.
This would work similarly in a PHP script with appropriate changes.
#!/usr/bin/perl
#
# Perl Script to determine if a call is in the local calling area
# Doug Crompton - 12/2006
#
# agi-local.agi
#
# Example in extensions.conf -
#
# exten => _215NXXXXXX,1,AGI(agi-local.agi)
# exten => _215NXXXXXX,n,Gotoif($[ ${localcall} = 1 ]? 10:20)
# exten => _215NXXXXXX,10,Dial(SIP/*82${EXTEN}@sipurafxo1,60,T) <<<
Local Call
# exten => _215NXXXXXX,11,Macro(failann,${DIALSTATUS})
# exten => _215NXXXXXX,20,Dial(SIP/${EXTEN}@gizmo,120,T) <<<
Non Local Call
# exten => _215NXXXXXX,21,Macro(failann,${DIALSTATUS})
#
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
$|=1;
my $lc = 0;
my $ret = 0;
if (my $exten = $input{'extension'}) {
my $area_code = substr($exten,0,3);
if ($area_code =~ /215|267|445/ ) {
$AGI->say_digits($area_code);
my $a215 = ($area_code =~ /215/);
my $a267 = ($area_code =~ /267/);
my $a445 = ($area_code =~ /445/);
my $exchange = substr($exten,3,3);
# Philadelphia Zone 4
# 215
$lc = $lc || ($a215 && ($exchange =~
/214|268|270|281|288|289|305|330|331|332|333|335|338|342|4
#267
$lc = $lc || ($a267 && ($exchange =~
/340|341|343|344|345|348|350|351|407|579|672|731/));
#
# Bensalem - Eddington - Cornwell Heights
# 215
$lc = $lc || ($a215 && ($exchange =~
/202|244|245|352|447|604|633|638|639|642|645|650|688|929/)
# 267
$lc = $lc || ($a267 && ($exchange =~
/223|332|520|522|523|525|526|527|529|681|704|771/));
#
# Bethayres - Huntingdon Valley
# 215
$lc = $lc || ($a215 && ($exchange =~
/344|544|914|938|947|974|975/));
# 267
$lc = $lc || ($a267 && ($exchange =~
/277|502|571|706|722|723|725|727|728|729/));
#
# Churchville - Feasterville
# 215
$lc = ($a215 && ($exchange =~
/322|354|355|357|364|396|436|485|494|526|791|876|942|953/));
# 267
$lc = $lc || ($a267 && ($exchange =~
/288|442|574|632|684|699|762|912|982|983|984|986|988|989|9
#
# Hatboro
# 215
$lc = $lc || ($a215 && ($exchange =~
/259|293|315|323|325|328|347|385|394|420|441|442|443|444|6
# 267
$lc = $lc || ($a267 && ($exchange =~
/220|280|282|317|387|532|537|615|732|803|960|961|963|965|9
#
# Langhorne
# 215
$lc = $lc || ($a215 && ($exchange =~
/359|375|478|539|702|710|741|750|752|757|809|891|970/));
# 267
$lc = $lc || ($a267 && ($exchange =~
/212|276|560|563|564|565|567|568|569|572|689|802|819|852/)
#
# Warrington
# 215
$lc = $lc || ($a215 && ($exchange =~
/318|343|488|491|792|798|918/));
# 267
$lc = $lc || ($a267 && ($exchange =~
/480|482|483|485|486|487|488|489|561|855|915|927/));
#
# Willow Grove
# 215
$lc = $lc || ($a215 && ($exchange =~
/346|366|392|395|449|657|658|659|706|784|830|882|902/));
# 267
$lc = $lc || ($a267 && ($exchange =~
/495|518|607|715|781|851|913|942|943|944|947|948|949/));
#
# Newtown
# 215
$lc = $lc || ($a215 && ($exchange =~
/434|497|504|550|579|860|867|944|968/));
# 267
$lc = $lc || ($a267 && ($exchange =~
/291|352|364|685|750|751|753|755|756|757|759/));
#
# Wycombe
# 215
$lc = $lc || ($a215 && ($exchange =~ /598/));
# 267
$lc = $lc || ($a267 && ($exchange =~
/396|491|493|494|719/));
#
if ($lc) {
$ret = 1;
$AGI->say_digits($exchange);
}
}
}
$AGI->set_variable('localcall',$ret);
exit;
More information about the asterisk-users
mailing list