All pastes #18346 Raw Edit

callback.agi

public text v1 · immutable
#18346 ·published 2005-07-23 19:01 UTC
rendered paste body
#!/usr/bin/perl

#use strict;

use File::Temp qw(tempfile);
use File::Copy;
use Asterisk::AGI;

$AGI = new Asterisk::AGI;

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

my $from;
my $trunk = "CAPI/0049221XXXX:b";
my $context = "disa";
my $extension = "s";
my $spooldir = "/var/spool/asterisk/outgoing";

print STDERR "AGI Environment Dump:\n";
foreach $i (sort keys %input)
{
  print STDERR " -- $i = $input{$i}\n";
}


my $callerid;
my $cidnumber;
my $channel;

$callerid = $input{callerid};
$cidnumber = $AGI->get_variable('cidnumber');
$AGI->exec('Congestion');

if ($cidnumber)
{
  $channel = $trunk . substr $cidnumber, 1;
}
else
{
  $channel = "Local/0" . $callerid . "\@local";
}

print STDERR "callback to channel: " . $channel . "\n";

my($fh, $filename) = tempfile();

print $fh <<EOD;
Channel: $channel
MaxRetries: 1
RetryTime: 60
WaitTime: 30
Context: $context
Extension: $extension
Priority: 1
Callerid: $callerid
EOD

close($fh);

copy $filename, '/tmp/lastcallback';
move $filename, $spooldir;