I’m trying to create a AGI Script for one extension that based in the calleridname should transfer the call to different extensions.
It’s for Asterisk 1.4, what i done it’s this:
#!/usr/bin/env perl
use Asterisk::AGI;
use strict;
use warnings;
use Switch;
$|=1;
my %AGI = new Asterisk::AGI;
my $tests = 0; my $fail =0; my $pass =0;
while (){
chomp;
last unless length($);
if (/^agi(\w+):\s+(.*)$/) {
$AGI{$1} = $2;
}
}
switch ($chan_vars{agi_calleridname}) {
case “Netdominium” { $AGI->exec(‘transfer’,‘SIP/1052’); }
# will be other cases here
else { $AGI->exec(‘transfer’,‘SIP/1001’); }
}
I have put this script just before hangup in that extension.
[quote=“david55”]I would suggest this was easier in plain dialplan.
Transfers takes a SIP URI, not an Asterisk technology/address string.[/quote]
So you are saying that instead of $AGI->exec(‘transfer’,‘SIP/1052’) Should be $AGI->exec(‘transfer’,‘SIP:1052@192.168.100.254’)?
This if for the receptionist. if she isn’t there the calls will be forwarded to the different offices anyway.
The asterisk box has like 20 lines and when a incoming call is received i change the calleridname based in the route, then the call goes to the receptionist and now she is transferring to the offices by hand, i want to make it automatic.
Assuming that the IP address is correct, yes. Most people would not transfer, but would rather relay the call with Dial. That is much better implemented in Asterisk, but does tie up capacity on the connection to the Asterisk box.
The error handling for Asterisk transfers is somewhat flakey.
I suspect what the receptionist is doing has an effect closer to an Asterisk Goto application call, i.e. it is redirecting to an extension, not a device, and the signalling path is being retained within Asterisk.
Again, I feel that you are making this unnecessarily difficult by using AGI.
After some time working on it i actually have made various scripts per incoming call route each one will call the receptionist 1 then the receptionist 2 and finally the costumer here is how i had done it:
Works like a charm
#!/usr/bin/perl
use strict;
use warnings;
use lib ‘/eos/pep/common’;
use lib ‘/var/lib/asterisk/agi-bin’;
use Asterisk::AGI;
use VoIP::Twinning;
use VoIP::Phones;
use VoIP::CallRecorder;
use VoIP::PHCIntegration;
use CommonAgis qw/:all/;
use Data::Dumper;
#constants
my $DEBUG = 1;
#create AGI object
my $AGI = new Asterisk::AGI();
my %input = $AGI->ReadParse();
$AGI->exec(‘NoOp’ , ‘DIAL’);
my $CR = new VoIP::CallRecorder();
#SAVE incoming callerIDnum
my $calleridnum = $AGI->get_variable(“CALLERID(number)”);
$AGI->set_variable(’__INBOUND_NUMBER’,$calleridnum);
my $call_args = $ARGV[3];
$AGI->verbose(‘CALL_ARGS:’ . $call_args) if $DEBUG;
my $dial_string = “SIP/reuniao-2|5|$call_args”;
my $dial_string2 = “SIP/reuniao-1|5|$call_args”;
my $dial_string3 = “SIP/1121|5|$call_args”;