On 9/07/2004 10:21 AM +0700, Isianto Istiadi wrote:

Dear guys,
I'm searching the wake-up call script in wiki, found one, but I have no
idea how to use it. Can you give some direction how to install it?
Thanks

I presume you're talking about this wake up call script: <http://www.voip-info.org/tiki-index.php?page=Asterisk%20tips%20wake-up>


Stick the following in cron:

* * * * * root /path/to/run_wakeups.sh

/path/to/run_wakeups.sh contains:

============= cut ==============
#!/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 test -r $fn
then
 /bin/mv -f $fn $OUTGOING/
 sleep $SLEEP
fi
done
============= cut ==============

The following is my wakeup.agi. Changes to the original version are: some debugging functionality (as I was troubleshooting an issue where it would read out the wrong time when the script tells you what time the wake up call was set to), and it also creates the /tmp/wakeups directory if it doesn't already exist. I suggest using the one on the voip-info.org page first, and if you decide to use my version then use at your own risk :)

============= cut ==============
#!/usr/bin/perl

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

use strict;

#########

# Settings:

my $pending_dir = '/tmp/wakeups';

unless (-d '/tmp/wakeups') {
       mkdir('/tmp/wakeups');
}

my $local_context = 'default';

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

my $debug = 1;

#my $application = 'MusicOnHold';
my $application = 'Playback';
my $data = 'wake-up';

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

#########

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

if ($debug) {
my $log = '/tmp/wakeup.log';
unlink($log);
open (DBG,">>$log") or die "Cannot open debug file: $!";
print DBG "\n" . "-" x 50 . "\n";
print DBG "Logging started: " . join('/', $mday, $mon, $year) . " " . join(':', $hour, $min, $sec) . "\n";
print DBG "-" x 50 . "\n";
}


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;

 print DBG 'HOUR entered: ' . $hour . "\n" if $debug;
 print DBG 'MINUTE entered: ' . $min . "\n" if $debug;

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

#   $agi->stream_file('pls-enter');
#   $agi->stream_file('digits/1');
#   $agi->stream_file('for');
#   $agi->stream_file('digits/a-m');
#   $agi->stream_file('or');
#   $agi->stream_file('digits/2');
#   $agi->stream_file('for');
#   my $ampm = $agi->get_data('digits/p-m', 15000, 1);
  my $ampm = $agi->get_data('am-or-pm', 15000, 1);
  exit if $ampm == -1;

  if ($ampm == 1)
  {
   $time = ParseDate(sprintf("%s:%02s AM", $hour, $min));
   print DBG 'TYPE entered: AM' . "\n" if $debug;
   print DBG '$time is set to: ' . $time . "\n" if $debug;
  }
  elsif ($ampm == 2)
  {
   $time = ParseDate(sprintf("%s:%02s PM", $hour, $min));
   print DBG 'TYPE entered: PM' . "\n" if $debug;
   print DBG '$time is set to: ' . $time . "\n" if $debug;
  }
  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');
print DBG 'UnixDate $time translates to ' . UnixDate($time, "%o") . "\n" if $debug;
print DBG 'localtime (UnixDate $time) translates to ' . localtime(UnixDate($time, "%o")) . "\n" if $debug;
$agi->exec('SayUnixTime', sprintf("%s||IMp", UnixDate($time, "%o")));


   $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)
{

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;

if ($debug) {
print DBG "\n" . "-" x 50 . "\n";
print DBG "Logging ended: " . join('/', $mday, $mon, $year) . " " . join(':', $hour, $min, $sec) . "\n";
print DBG "-" x 50 . "\n";
close(DBG);
}
============= cut ==============


Last, but not least, you just need an entry in your extensions.conf similar to:

exten => 999,1,AGI(/path/to/wakeup.agi)

Reload asterisk and you should now be able to dial 999 and set a wakeup call. Oh, also very important, you need to create the sound files (using wavepad or some other software to create gsm files) required in this script. These include:

wakeup-menu.gsm (eg. "Welcome to the wakeup call service. Please enter the time for your wakeup call... etc")
for.gsm
extension.gsm


If you got any problems, check out the asterisk console for any errors.

Hope this helps.

Regards,
Gonzalo
_______________________________________________
Asterisk-Users mailing list
[EMAIL PROTECTED]
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to