On Sat, Feb 28, 2004 at 11:03:41PM -0600, Robert Lawrence wrote:
> I would be interested in the AGI Script.

Here it is, along with the shell script I run from cron every minute.
It's sloppy -- I didn't expect to be sharing it so quickly.

Rob

-- 
Rob Fugina, Systems Guy
[EMAIL PROTECTED] -- http://www.geekthing.com
My firewall filters MS Office attachments.

IBM = Institute of Black Magic
#!/bin/bash

PENDING=/tmp/wakeups
OUTGOING=/var/spool/asterisk/outgoing
SLEEP=5

TIME=$(/bin/date +%H%M)

for fn in $PENDING/$TIME.*.call
do
        if [ -r $fn ]
        then
                /bin/mv -vf $fn $OUTGOING/
                sleep $SLEEP
        fi
done

#!/usr/bin/perl

use Asterisk::AGI;
use Date::Manip;

use strict;

#########

# Settings:

my $pending_dir = '/tmp/wakeups';

my $local_context = 'inside';

# values for the call file:
my $maxretries = 3;
my $retrytime = 60;
my $waittime =  30;

my $application = 'MusicOnHold';
my $data = 'default';

my $callerid = 'Wakeup Call Service <297>';

#########

my $agi = new Asterisk::AGI;
my %stuff = $agi->ReadParse;    # MUST DO THIS! -- (add this to constructor!)

# this says "1 to create, 2 to confirm, 3 to cancel"
my $func = $agi->get_data('wakeup-menu', 20000, 1);

exit if $func == -1;

my ($caller) = $stuff{callerid} =~ /<(\d+)>/;

if ($func == 1)
{
        my $time = $agi->get_data('time', 15000, 4);
        exit if $func == -1;

        if ($time =~ /^(\d{2})(\d{2})$/)
        {
                my $hour = $1 * 1;
                my $min = $2;

                if ($hour > 0 && $hour <= 12 && $min < 60)
                {
                        my $time;

                        $agi->stream_file('digits/1');
                        $agi->stream_file('digits/a-m');
                        $agi->stream_file('digits/2');
                        my $ampm = $agi->get_data('digits/p-m', 15000, 1);
                        exit if $ampm == -1;

                        if ($ampm == 1)
                        {
                                $time = ParseDate(sprintf("%s:%02s AM", $hour, $min));
                        }
                        elsif ($ampm == 2)
                        {
                                $time = ParseDate(sprintf("%s:%02s PM", $hour, $min));
                        }
                        else
                        {
                                $agi->stream_file('vm-sorry');
                        }

                        if ($time)
                        {
                                my $h = UnixDate($time, "%I") * 1;
                                my $m = UnixDate($time, "%M");
                                my $a = UnixDate($time, "%p");

                                foreach my $fn (<$pending_dir/*.$caller.call>)
                                {
                                        unlink $fn;
                                }

                                my $filename = sprintf("%s/%04s.%s.call", 
$pending_dir, UnixDate($time, "%H%M"), $caller);

                                open(FILE, ">$filename");

                                printf FILE q{#
Channel: Local/[EMAIL PROTECTED]

MaxRetries: %s
RetryTime: %s
WaitTime: %s

Application: %s
Data: %s

Callerid: %s
},
        $caller, $local_context,
        $maxretries,
        $retrytime,
        $waittime,
        $application,
        $data,
        $callerid,
        ;

                                close(FILE);

                                # say "Your wakeup call"
                                $agi->stream_file('has-been-set-to');
                                $agi->exec('SayUnixTime', sprintf("%s||IMp", 
UnixDate($time, "%s")));

                                $agi->stream_file('for');
                                $agi->stream_file('extension');
                                $agi->say_digits($caller);

                                $agi->stream_file('auth-thankyou');
                        }
                }
                else
                {
                        $agi->stream_file('vm-sorry');
                }

        }
        else
        {
                $agi->stream_file('vm-sorry');
        }
}
elsif ($func == 2)
{
        # say "Your wakeup call"

        my ($fn) = <$pending_dir/*.$caller.call>;

        if ($fn)
        {
                my ($time) = $fn =~ /\/(\d{4})\.\d+\.call/;
                $time =~ s/(\d\d)(\d\d)/$1:$2/;

                $agi->stream_file('is-set-to');

                $agi->exec('SayUnixTime', sprintf("%s||IMp", 
UnixDate(ParseDate($time), "%s")));
        }
        else
        {
                $agi->stream_file('is-not-set');
        }

        $agi->stream_file('auth-thankyou');
}
elsif ($func == 3)
{

        foreach my $fn (<$pending_dir/*.$caller.call>)
        {
                unlink $fn;
        }

        # say "Your wakeup call"
        $agi->stream_file('has-been-cleared');
        $agi->stream_file('auth-thankyou');
}
elsif ($func eq '*')
{
        $agi->stream_file('vm-sorry');
}
else
{
        $agi->stream_file('vm-sorry');
}

$agi->hangup;









Reply via email to