[asterisk-users] Best practices to route calls according holidays
Ron Bergin
rkb at i.frys.com
Sat May 19 08:54:20 CDT 2012
Olivier wrote:
> Hi,
>
> At the moment, I'm mostly using a "Day/Night toggle" button to let
> users deal with week-ends, holidays and opening hours.
> As Asterisk 1.8 introduces Calendar capabilities, I'm wondering if
> better alternatives now exist.
>
> Is it possible, safe, reliable and easy to refer from Asterisk to a
> public calendar resource listing holidays, for a given country ?
> Should you instead refer to a private resource, to avoid depending on
> an externaly managed resource ? If you go this way, which tools would
> you recommend to build and update a private calendar ?
>
> Suggestions ?
>
> Regards
>
> --
The database approach that others have suggested sounds pretty good. What
I did was to write a simple agi script that dispatches a subroutine based
on the holiday. I hard coded the holidays in the script, but they could
just as easily be stored in a db.
Here's the key portion of the script. (The formatting may get goofed up
in the email).
#!/usr/bin/perl
use strict;
use warnings;
use Asterisk::AGI;
use Date::Calendar;
$|++;
my ($min, $hr, $day, $mo, $yr, $dow) = (localtime)[1..6];
$mo++;
$yr += 1900;
my $today = sprintf("%d%02d%02d", $yr,$mo,$day);
my $holidays = {
"New Year's Day" => "#Jan/1",
"Easter" => "+0",
"Memorial Day" => "5/Mon/May",
"Independence Day" => "#Jul/4",
"Labor Day" => "1/Mon/Sep",
"Thanksgiving" => "4/Thu/Nov",
"Black Friday" => "4/Fri/Nov",
"Christmas Eve" => "#Dec/24",
"Christmas Day" => "#Dec/25",
"Christmas Dayafter" => "#Dec/26",
"New Year's Eve" => "#Dec/31"
};
my %dispatch = (
"New Year's Day" => \&new_years_day,
"Easter" => \&easter,
"Memorial Day" => \&memorial_day,
"Independence Day" => \&july4,
"Labor Day" => \&labor_day,
"Thanksgiving" => \&thanksgiving,
"Black Friday" => \&black_friday,
"Blackout Period" => \&blackout_hrs,
"Christmas Eve" => \&christmas_eve,
"Christmas Day" => \&christmas_day,
"Christmas Dayafter" => \&christmas_dayafter,
"New Year's Eve" => \&new_years_eve,
);
my $agi = Asterisk::AGI->new;
my $calendar = Date::Calendar->new( $holidays );
$calendar->year( $yr );
foreach my $holiday ( keys %$holidays ) {
my @holiday = $calendar->search( $holiday );
my $holidaydate = sprintf("%d%02d%02d", $holiday[0]->year,
$holiday[0]->month,
$holiday[0]->day
);
if ( $today == $holidaydate ) {
$dispatch{ $holiday }->($agi);
exit;
}
}
if ( in_blkout_period( $today ) ) {
$dispatch{"Blackout Period"}->( $agi, $dow, $hr );
exit;
}
##########################################################################
sub playback {
my ($agi, $holiday, $hrs) = @_;
$agi->stream_file([
'frys/thank_you_for_calling',
"frys/$holiday",
"frys/$hrs",
'frys/enjoy',
'frys/frys_goodbye'
]
);
}
sub new_years_day {
my $agi = shift;
$agi->exec('noop', "Incoming call on New Year's Day");
if ($hr < 10 or $hr >= 19) {
playback($agi, 'new_years_day', '10to7');
$agi->hangup();
}
else {
$agi->exec('Goto', 'welcome');
}
}
--
Ron Bergin
Network Operations Administrator
Fry's Electronics, Inc.
More information about the asterisk-users
mailing list