#!/usr/bin/perl
use strict;
use Asterisk::AGI;
my ($sec,$min,$hour,$mday,$mon,
$year,$wday,$yday,$isdst) = localtime(time);
my $yyyymmdd = sprintf ("%04d%02d%02d",$year+1900,$mon+1,$mday);
my $month = $mon + 1;
my $vm_sound_dir = "vm-sounds";
my $office_presence_file = "/path/to/file/office.presence.txt";
my $AGI = Asterisk::AGI->new;
my %input = $AGI->ReadParse;
my $greeting_start = "start";
my $greeting_end_in_office = "endnormal";
my $greeting_end_out_of_office = "endooo";
my $weekday_sound = "wday" . $wday;
my $mday_sound = $mday;
my $month_sound = "month" . $month;
my @files_to_play = ();
push @files_to_play, $greeting_start;
push @files_to_play, $weekday_sound;
push @files_to_play, $month_sound;
push @files_to_play, $mday;
if (-e $office_presence_file or $hour == 8) {
push @files_to_play, $greeting_end_in_office;
} else {
push @files_to_play, $greeting_end_out_of_office;
}
foreach my $sound (@files_to_play) {
$AGI->verbose("Playing sound $sound");
$AGI->stream_file("$vm_sound_dir/$sound");
}