Skip to content

Instantly share code, notes, and snippets.

@wmw
Created April 18, 2009 00:57
Show Gist options
  • Save wmw/97371 to your computer and use it in GitHub Desktop.
Save wmw/97371 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use Asterisk::AGI;
use strict;
sub debug ( $ );
# all sound paths are relative to /var/lib/asterisk/sounds
# asterisk appends the proper extension, don't provide it
my $ENTER_PIN = 'custom/enter_pin';
my $ENTER_CALLERID_APPEARANCE
= 'custom/enter_callerid_appearance';
my $ENTER_TN_TO_CALL = 'custom/enter_tn_to_call';
my $TRYING_TO_CONNECT = 'custom/trying_to_connect_your_call';
my $FAIL = 'custom/failed.gsm';
my $OK = 'custom/press_1_if_correct_2_if_not';
my $PIN_CODE = '1234';
my $TRUNK = "Zap/g2";
my $tnCallerID = '';
my $tnDestination = '';
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
$AGI->answer();
read_pin: {
my $pin = $AGI->get_data($ENTER_PIN,-1,1); if (!$pin || $pin eq "" ) {
goto read_pin; }
wait_for_digit: {
my $ascii_code = $AGI->wait_for_digit(3000);
my $digit = chr($ascii_code);
if ($digit eq "#") {
last;
} elsif (!$digit || $digit eq "") {
goto wait_for_digit;
} else {
$pin .= $digit; }
goto wait_for_digit;
};
if ($pin != $PIN_CODE) {
goto read_pin; }
};
read_tnCallerID: {
$tnCallerID = $AGI->get_data($ENTER_CALLERID_APPEARANCE, -1, 1);
if (!$tnCallerID || $tnCallerID eq "") {
goto read_tnCallerID; }
wait_for_digit: {
my $ascii_code = $AGI->wait_for_digit(3000);
my $digit = chr($ascii_code);
if ($digit eq "#") {
last;
} elsif (!$digit || $digit eq "") {
goto wait_for_digit;
} else {
$tnCallerID .= $digit;
}
goto wait_for_digit;
};
$AGI->say_digits($tnCallerID);
my $isOK = $AGI->get_data($OK, -1, 1);
if ($isOK == 1) {
last;
} else {
goto read_tnCallerID; }
};
read_tnDestination: {
$tnDestination = $AGI->get_data($ENTER_TN_TO_CALL, -1, 10);
$AGI->say_digits($tnDestination);
my $isOK = $AGI->get_data($OK, -1, 1);
if ($isOK == 1) {
last;
} else {
goto read_tnDestination; }
};
$AGI->stream_file($TRYING_TO_CONNECT);
$AGI->set_callerid($tnCallerID);
$AGI->exec('Dial',"$TRUNK/$tnDestination");
$AGI->hangup();
exit(0);
sub debug ( $ )
{
my $msg = shift || 'NoOp';
$AGI->verbose($msg,3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment