All pastes #19512 Raw Edit

Mine

public text v1 · immutable
#19512 ·published 2005-08-07 18:00 UTC
rendered paste body
# Set the verbosity level of informational message, undefined or Asterisk verbosity level
$verbose = 1;

use File::Basename;
use Asterisk::AGI;
use Asterisk::Outgoing;

$AGI = new Asterisk::AGI;
%input = $AGI->ReadParse();
$AGI->setcallback(\&mycallback);

my ($outgoingclid, $broadcastclid, $broadcastext, $regextension, $context, $outgoingcontext, $accountcode) = @ARGV;
# outgoingclid = Outgoing Callerid info
# broadcastclid = Callerid number of person who goes into special extension ie "moderator"
# broadcastext = The special extension see above
# regextension = Typical extension
# context = The context to place the calls in
# outgoingcontext = Calls are placed using the "Local" channel.  This specifies the context to use.
# accountcode = What accountcode does this call belong to.

#$dir = dirname($0);

sleep(1);
#if ($ARGV[0] ne "") {
#  verbose("CALLBACK: Outcall");
#  if ($ARGV[0] ne "noextension") {
#    verbose("CALLBACK: Extension $ARGV[0].");
#    $AGI->exec("SendDTMF", "$ARGV[0]");
#    sleep(2);
#  };
#  for ($count=0; $count < 7; $count++) {
#    $AGI->stream_file("outcall");
#  };
#  exit(0);
#};

$clidnumber = $input{'callerid'};
$clidnumber =~ s/\"//g;
if ($clidnumber =~ /^(\d+)\D/) {
        $clidnumber = $1;
}

if ($clidnumber =~ /^\d\d\d\d\d\d\d\d\d\d$/) {
        if ($clidnumber == $broadcastclid) {
                $confirmed = "1";
                $response = "1";
        } else {
                $AGI->stream_file("the-num-i-have-is");
                $AGI->say_digits($clidnumber);
                $AGI->stream_file("correct"); # Is this the number you wish to be called at?
                $response = $AGI->get_data("1-yes-2-no", "5000", "1");
                if ($response eq "1") {
                        $confirmed = "1";
                        $response = "1";
                } else {
                $clidnumber = $AGI->get_data("get-phonenumber"); # Please enter the phone number followed by the pound sign
                        verbose("CALLBACK: Get Phone Number.");
                };
        };
} else {
    $clidnumber = $AGI->get_data("get-phonenumber");
    verbose("CALLBACK: Get Phone Number.");
};

if ($clidnumber =~ /^\d\d\d\d\d\d\d\d\d\d$/) {
  verbose("CALLBACK: Valid callback.");
  $channel = "Local\/"."1".$clidnumber."\@$outgoingcontext";
} else {
  verbose("CALLBACK: Valid callback.");
  $channel = "Local\/".$clidnumber."\@$outgoingcontext";
};

if ($channel eq "") {
  verbose("CALLBACK: Bad phone number $clidnumber.  Exiting!");
  $AGI->say_digits("$clidnumber");
  $AGI->stream_file("notvalid");
  exit(0);
};
verbose("CALLBACK: Get extension.");
if ($clidnumber == $broadcastclid) {
        $extension = $broadcastext;
        $channel = "Local\/"."1".$clidnumber."\@$outgoingcontext";
} else {
        $extension = $AGI->get_data("enter-extension");
};

if (!defined($confirmed)) {
        verbose("CALLBACK: Request confirmation.");
        $AGI->stream_file("the-num-i-have-is");
        $AGI->say_digits("$clidnumber");
        if ($extension ne "") {
                 $AGI->stream_file("extension");
                 $AGI->say_digits("$extension");
        };
        $AGI->say_digits($clidnumber);
        $AGI->stream_file("correct"); #the number you wish to be called at?
        $response = $AGI->get_data("1-yes-2-no", "5000", "1");
};

if (!defined($extension)) {
        $extension = $regextension; #"8200";
};

if ($response eq "1") {
  verbose("CALLBACK: Callback to $clidnumber confirmed.");
  $out = new Asterisk::Outgoing;
  $out->setvariable("Channel", "$channel");
  $out->setvariable("MaxRetries", "0");
  $out->setvariable("context", "$context");
  $out->setvariable("extension", "$extension");
  $out->setvariable("CallerID", "$outgoingclid $clidnumber");
  $out->setvariable("Account", "$accountcode");
  $out->outtime(time() + 15);
  $out->create_outgoing;
  $AGI->stream_file("callback-confirmed");
} else {
    verbose("CALLBACK: Callback to $clidnumber canceled!");
    $AGI->stream_file("canceled");
    $AGI->stream_file("please-hang-up-and-try-again");
};


sub mycallback {
        my ($returncode) = @_;
        print STDERR "MYCALLBACK: User Hungup ($returncode)\n";
        exit($returncode);
}

sub verbose {
  if (defined($verbose)) {
    $AGI->verbose("@_", $verbose);
    return(0);
  };
};