Upgrade 3CX to v18 and get it hosted free!

Asterisk tips openclose.agi

Author image

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)

 


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.