<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.10.1">
</HEAD>
<BODY>
Hi All,<BR>
<BR>
I have been attempting to get an AGI LCRdialout script to work. Basically what I need to have happen is when someone dials out a number the script check to see if it is local if so, go out the ZAP channel. If the ZAP channel is busy, go out the IAX channels, if IAX is all busy, go out the SIP channels. Here is a sample of what I have in my script. <BR>
<BR>
<BR>
#!/usr/bin/perl<BR>
<BR>
use strict;<BR>
use Asterisk::AGI;<BR>
<BR>
my $callerId = "MyNumber";<BR>
my $log = "/var/log/asterisk/dialout.log";<BR>
my $gIaxUser = "MyIAXPROVIDER";<BR>
my $gIaxPass = "MYIAXPASS";<BR>
my $gIaxHost = "myIAXHost";<BR>
my $gSipHost = "MYSIPHost";<BR>
<BR>
########### SYSTEM VARIABLES #####################<BR>
my $AGI = new Asterisk::AGI;<BR>
my $gDialedNo = shift;<BR>
my $gNumber = "";<BR>
my $gPrefix = "";<BR>
my $gAreaCode = "";<BR>
<BR>
### Sets Outbound CallerID ###<BR>
$AGI->set_callerid($callerId);<BR>
<BR>
open(LOG, ">>$log") or die("Couldn't open $log\n");<BR>
<BR>
### Log Statement for Troubleshooting ###<BR>
#print LOG "(". localtime() .") Got Dialed number: $gDialedNo\n";<BR>
<BR>
### Calls the function parseDialed to seperate the dialed number into areacode, ###<BR>
### prefix, and number and assigns it to the num array ###<BR>
my @num = parseDialed($gDialedNo);<BR>
if(!@num) {<BR>
### Log Statement for Troubleshooting ###<BR>
#print LOG "(". localtime() .") ERROR: Number not Valid!\n";<BR>
<BR>
### If num is empty DIE ###<BR>
return -1;<BR>
} else {<BR>
### Otherwise grab the items from the array ###<BR>
$gNumber = pop(@num);<BR>
$gPrefix = pop(@num);<BR>
$gAreaCode = pop(@num);<BR>
<BR>
$gPrefix = pop(@num);<BR>
$gAreaCode = pop(@num);<BR>
<BR>
### Log Statement for Troubleshooting ###<BR>
#print LOG "(". localtime() .") Set Areacode: $gAreaCode - Prefix: $gPrefix - Number: $gNumber\n";<BR>
}<BR>
<BR>
### Calls the function genDialString to create the actual dial string depending on what was dialed ###<BR>
my $retDialStr = genDialString($gAreaCode,$gPrefix,$gNumber,$gIaxUser,$gIaxPass,$gIaxHost,$gSipHost);<BR>
if(!$retDialStr) {<BR>
### Log Statement for Troubleshooting ###<BR>
#print LOG "(". localtime() .") ERROR: No Dial String!\n";<BR>
<BR>
### If DialString is empty then DIE ###<BR>
return -1;<BR>
} else {<BR>
### Log Statement for Troubleshooting ###<BR>
print LOG "(". localtime() .") Dialing: $retDialStr\n";<BR>
<BR>
### Otherwise Dial the number over the specified channel ###<BR>
$AGI->exec("$retDialStr");<BR>
my $res = shift;<BR>
<BR>
print LOG "(". localtime() .") Result: $res\n";<BR>
}<BR>
close(LOG);<BR>
sub parseDialed {<BR>
my $dialedNo = shift;<BR>
my @number;<BR>
<BR>
### If the dialed number is 12 digits parse into seperate areacode, prefix, and number ###<BR>
if(length($dialedNo) == 12) {<BR>
push(@number, substr($dialedNo, 2, 3));<BR>
push(@number, substr($dialedNo, 5, 3));<BR>
push(@number, substr($dialedNo, 5));<BR>
return @number;<BR>
### Else Assume it is in our areacode and grab the rest of the digits. ###<BR>
} elsif(length($dialedNo) == 8) {<BR>
push(@number, "435");<BR>
push(@number, substr($dialedNo, 1, 3));<BR>
push(@number, substr($dialedNo, 1));<BR>
return @number;<BR>
### Else assume it is an invalid number or not enough digits and bread out fail safe ###<BR>
return @number;<BR>
### Else assume it is an invalid number or not enough digits and bread out fail safe ###<BR>
} else {<BR>
return @number;<BR>
}<BR>
### Final catch all for invalid number ###<BR>
return @number;<BR>
}<BR>
sub genDialString {<BR>
my $areaCode = shift;<BR>
my $prefix = shift;<BR>
my $number = shift;<BR>
my $iaxUser = shift;<BR>
my $iaxPass = shift;<BR>
my $iaxHost = shift;<BR>
my $sipHost = shift;<BR>
my $one = "1";<BR>
my $dialStr = "";<BR>
my $callStatus = "";<BR>
my $channel = "";<BR>
<BR>
### If they dialed toll free dial on local PSTN ###<BR>
if($areaCode eq "800" || $areaCode eq "866" || $areaCode eq "877" || $areaCode eq "888") {<BR>
$dialStr = "Dial Zap/g2/$one$areaCode$number|25|TW";<BR>
<BR>
### Log Statement for Troubleshooting ###<BR>
#print LOG "(". localtime() .") Toll Free: $dialStr\n";<BR>
<BR>
return $dialStr;<BR>
### Else if it is a 435 areacode ###<BR>
} elsif($areaCode eq "435") {<BR>
### If areacode is 435 and the prefix is local to us, Dial out over ZAP/PSTN line ###<BR>
if($prefix eq "215" || $prefix eq "229" || $prefix eq "236" || $prefix eq "251" || $prefix eq "256" || $prefix eq "275" ||<BR>
$prefix eq "313" || $prefix eq "467" || $prefix eq "619" || $prefix eq "627" || $prefix eq "628" || $prefix eq "632" ||<BR>
$prefix eq "634" || $prefix eq "635" || $prefix eq "652" || $prefix eq "656" || $prefix eq "668" || $prefix eq "669" ||<BR>
$prefix eq "673" || $prefix eq "674" || $prefix eq "680" || $prefix eq "688" || $prefix eq "703" || $prefix eq "705" ||<BR>
$prefix eq "772" || $prefix eq "773" || $prefix eq "862" || $prefix eq "986") {<BR>
$dialStr = "Dial Zap/g2/$number|25|TW";<BR>
<BR>
### Log Statement for Troubleshooting ###<BR>
#print LOG "(". localtime() .") Local Call: $dialStr\n";<BR>
<BR>
return $dialStr;<BR>
### Else it is not local to us, Dial out over IAX Provider ###<BR>
} else {<BR>
$dialStr = "Dial IAX2/$iaxUser\:$iaxPass\@$iaxHost/$one$areaCode$number|25|TW";<BR>
<BR>
### Log Statement for Troubleshooting ###<BR>
#print LOG "(". localtime() .") Non-Local Call: $dialStr\n";<BR>
<BR>
return $dialStr;<BR>
}<BR>
### Else it is not local to us, Dial out over IAX Provider ###<BR>
} else {<BR>
$dialStr = "Dial IAX2/$iaxUser\:$iaxPass\@$iaxHost/$one$areaCode$number|25|TW";<BR>
<BR>
### Log Statement for Troubleshooting ###<BR>
#print LOG "(". localtime() .") Non-Local Call: $dialStr\n";<BR>
<BR>
return $dialStr;<BR>
}<BR>
### Final catch all for invalid number ###<BR>
return $dialStr;<BR>
}<BR>
<BR>
<BR>
Can someone give me some advice as to how to get a channel status of what the $AGI just dialed.<BR>
<BR>
<BR>
Thanks in advance,<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<B><I><FONT SIZE="4"><FONT COLOR="#000080">Jon Scottorn</FONT></FONT></I></B>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>