Asterisk tips openclose.agi

How to play different greetings based on time and date

Lets play a nighttime or daytime greeting and then continue
in the current context.

Place this in your agi-bin directory (usually /var/lib/asterisk/agi-bin):

  1. !/bin/sh
  2. Done by Alex Lopez (alex.lopez (at) O p s y s (dot) com)
  3. You may need to change the [if/than] logic depending on OS and Shell implementation.
TODAY=`date +%m%d%y`
TODAYSHORT=`date +%m%d`
DAY=`date +%a`
HOUR=`date +%H`
MINUTE=`date +%M`
TIMENOW=$HOUR$MINUTE
STATUS=closed
case "$TODAYSHORT" in
0101 ) STATUS=holiday;; # New Years Day
0704 ) STATUS=holiday;; # July Forth
1224 ) STATUS=halfday;; # Christmas Eve
1225 ) STATUS=holiday;; # Christmas Day
1226 ) STATUS=holiday;; # Year End holiday
1227 ) STATUS=holiday;; # Year End holiday
1228 ) STATUS=holiday;; # Year End holiday
1229 ) STATUS=holiday;; # Year End holiday
1230 ) STATUS=holiday;; # Year End holiday
1231 ) STATUS=holiday;; # Year End holiday
esac
case "$TODAY" in
090505 ) STATUS=holiday;; # Labor Day
112405 ) STATUS=holiday;; # Thanksgiving
112505 ) STATUS=holiday;; # Day after ThanksGiving
052906 ) STATUS=holiday;; # Memorial Day
090406 ) STATUS=holiday;; # Labor Day
112306 ) STATUS=holiday;; # Thanksgiving
112406 ) STATUS=holiday;; # Day after ThanksGiving
052807 ) STATUS=holiday;; # Memorial Day
090307 ) STATUS=holiday;; # Labor Day
112207 ) STATUS=holiday;; # Thanksgiving
112307 ) STATUS=holiday;; # Day after ThanksGiving
052608 ) STATUS=holiday;; # Memorial Day
090108 ) STATUS=holiday;; # Labor Day
112708 ) STATUS=holiday;; # Thanksgiving
112808 ) STATUS=holiday;; # Day after ThanksGiving
esac
if test "$STATUS" != "holiday" -a \
"$DAY" != "Sat" -a \
"$DAY" != "Sun" -a \
"$TIMENOW" -gt "0800" -a \
"$TIMENOW" -lt "1900"
then
STATUS=open
fi
if test "$STATUS" = "halfday" -a \
"$TIMENOW" -gt "0800" -a \
"$TIMENOW" -lt "1200"
then
STATUS=open
fi
if test "$DAY" = "Sat" -a \
"$TIMENOW" -gt "0900" -a \
"$TIMENOW" -lt "1600"
then
STATUS=open
fi
if test "$DAY" = "Sun" -a \
"$TIMENOW" -gt "0900" -a \
"$TIMENOW" -lt "1300"
then
STATUS=open
fi
  1. Until I can get the Holiday logic done in extensions.conf
  2. We Be CLOSED!!!
if test "$STATUS" = "holiday"
then
STATUS=closed
fi
echo "SET VARIABLE status $STATUS \"\""

You can use it with an dial-plan (see extensions.conf) like this:

exten => s,1,Wait,2 ; Allow for PRI to grab info in facility
exten => s,2,AGI(openclose.agi)
exten => s,3,GotoIf($[${STATUS} = closed]?6:4)
exten => s,4,GotoIf($[${STATUS} = holiday]?8:10)
exten => s,5,Goto(s,12)
exten => s,6,BackGround(nighttime-greeting)
exten => s,7,Goto(s,12)
exten => s,8,BackGround(holiday-greeting)
exten => s,9,Goto(s,12)
exten => s,10,BackGround(daytime-greeting)
exten => s,11,NoOp
exten => s,12,BackGround(mainmenu)

How to play different greetings based on time and date

Lets play a nighttime or daytime greeting and then continue
in the current context.

Place this in your agi-bin directory (usually /var/lib/asterisk/agi-bin):

  1. !/bin/sh
  2. Done by Alex Lopez (alex.lopez (at) O p s y s (dot) com)
  3. You may need to change the [if/than] logic depending on OS and Shell implementation.
TODAY=`date +%m%d%y`
TODAYSHORT=`date +%m%d`
DAY=`date +%a`
HOUR=`date +%H`
MINUTE=`date +%M`
TIMENOW=$HOUR$MINUTE
STATUS=closed
case "$TODAYSHORT" in
0101 ) STATUS=holiday;; # New Years Day
0704 ) STATUS=holiday;; # July Forth
1224 ) STATUS=halfday;; # Christmas Eve
1225 ) STATUS=holiday;; # Christmas Day
1226 ) STATUS=holiday;; # Year End holiday
1227 ) STATUS=holiday;; # Year End holiday
1228 ) STATUS=holiday;; # Year End holiday
1229 ) STATUS=holiday;; # Year End holiday
1230 ) STATUS=holiday;; # Year End holiday
1231 ) STATUS=holiday;; # Year End holiday
esac
case "$TODAY" in
090505 ) STATUS=holiday;; # Labor Day
112405 ) STATUS=holiday;; # Thanksgiving
112505 ) STATUS=holiday;; # Day after ThanksGiving
052906 ) STATUS=holiday;; # Memorial Day
090406 ) STATUS=holiday;; # Labor Day
112306 ) STATUS=holiday;; # Thanksgiving
112406 ) STATUS=holiday;; # Day after ThanksGiving
052807 ) STATUS=holiday;; # Memorial Day
090307 ) STATUS=holiday;; # Labor Day
112207 ) STATUS=holiday;; # Thanksgiving
112307 ) STATUS=holiday;; # Day after ThanksGiving
052608 ) STATUS=holiday;; # Memorial Day
090108 ) STATUS=holiday;; # Labor Day
112708 ) STATUS=holiday;; # Thanksgiving
112808 ) STATUS=holiday;; # Day after ThanksGiving
esac
if test "$STATUS" != "holiday" -a \
"$DAY" != "Sat" -a \
"$DAY" != "Sun" -a \
"$TIMENOW" -gt "0800" -a \
"$TIMENOW" -lt "1900"
then
STATUS=open
fi
if test "$STATUS" = "halfday" -a \
"$TIMENOW" -gt "0800" -a \
"$TIMENOW" -lt "1200"
then
STATUS=open
fi
if test "$DAY" = "Sat" -a \
"$TIMENOW" -gt "0900" -a \
"$TIMENOW" -lt "1600"
then
STATUS=open
fi
if test "$DAY" = "Sun" -a \
"$TIMENOW" -gt "0900" -a \
"$TIMENOW" -lt "1300"
then
STATUS=open
fi
  1. Until I can get the Holiday logic done in extensions.conf
  2. We Be CLOSED!!!
if test "$STATUS" = "holiday"
then
STATUS=closed
fi
echo "SET VARIABLE status $STATUS \"\""

You can use it with an dial-plan (see extensions.conf) like this:

exten => s,1,Wait,2 ; Allow for PRI to grab info in facility
exten => s,2,AGI(openclose.agi)
exten => s,3,GotoIf($[${STATUS} = closed]?6:4)
exten => s,4,GotoIf($[${STATUS} = holiday]?8:10)
exten => s,5,Goto(s,12)
exten => s,6,BackGround(nighttime-greeting)
exten => s,7,Goto(s,12)
exten => s,8,BackGround(holiday-greeting)
exten => s,9,Goto(s,12)
exten => s,10,BackGround(daytime-greeting)
exten => s,11,NoOp
exten => s,12,BackGround(mainmenu)

Created by: opsys, Last modification: Mon 23 of Apr, 2012 (23:37 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+