Play Different Greeting on Schedule

I have a PBX setup with Asterisk 18 and I would like to find the best way to change greetings for inbound calls based on a schedule.

Currently, all inbound calls go to the Inbound context. A series of GotoIfTime statements are used to determine if it is a holiday or if it is outside of normal business hours. If it is a holiday or outside of normal business hours, the call is sent to the Closed context where a greeting is played and the call is transferred to our answering service. If it is not a holiday and inside of our normal business hours, the call is sent to the Open context.

What I would like to do is to change the greeting played in the Closed context based on if it is a holiday and which holiday. I can think of a few ways to accomplish this: 1) use global variables for the greeting file name or 2) break playback of the greeting into its own sub and pass the greeting name as a parameter or 3) have a context for each holiday with the greeting playback.

I would appreciate some input on the cleanest approach our any recommendations on how I can improve my inbound call routing.

Below is a excerpt of the relevant parts of my extensions.conf:

[Inbound]
; 24-Hour Number
exten => 5552424,Verbose(1,"${CALLERID(num)} called the 24-hour number")
 same => n,Queue(all-phones,Cr)
 same => n,Hangup()


; Check holidays & business hours
; Holidays
exten => _X.,1,Verbose(1,"Check business hours/holidays ${CALLERID(num)} -> ${EXTEN}", 1)
; Test Time Conditions
; same => n,Verbose(1,"Time is ${STRFTIME()}")
; same => n,Set(TESTTIME(date,time)=2024/05/03 8:30:00 America/New_York)
; same => n,Verbose(1,"Time is ${STRFTIME()}")

; Memorial Day 2024
; same => n,GotoIfTime(*,Mon,24-29,may,?Closed,s,1)

; Fourth of July
 same => n,GotoIfTime(*,*,4-5,jul?Closed,s,1)

; Labor Day
 same => n,GotoIfTime(*,mon,1-7,sep?Closed,s,1)

; Thanksgiving
 same => n,GotoIfTime(*,thu,22-28,nov?Closed,s,1)
 same => n,GotoIfTime(*,fri,22-28,nov?Closed,s,1)

; Christmas
 same => n,GotoIfTime(7:00-12:00,tue,24,dec?Open,${EXTEN},1:Closed,s,1)
 same => n,GotoIfTime(*,*,25-29,dec?Closed,s,1)

; New Years
 same => n,GotoIfTime(*,*,31,dec?Closed,s,1)

; Business Hours (Mon-Fri 8 AM - 5 PM, 1)
 same => n,GotoIfTime(7:00-17:00,mon-fri,*,*?Open,${EXTEN},1:Closed,s,1)

[Open]
; Branch Office inbound 
exten => 5552222,1,Verbose(1,"Inbound call for branch office from ${CALLERID(name)} (${CALLERID(num)})")
 same => n,Dial(PJSIP/5553333@sip-trunk)
 same => n,Hangup()

; Main Office inbound
exten => 5551111,1,Verbose(1,"Inbound call for main office from ${CALLERID(name)} (${CALLERID(num)})")
 same => n,Playback(/usr/share/asterisk/sounds/custom/greeting-open)
 same => n,Set(ATTEMPT=0)
 same => n,While($[${ATTEMPT}<3])
 same => n,Set(KEY=0)
 same => n,Read(KEY,/usr/share/asterisk/sounds/custom/continue-call-press-one,1)
 same => n,GotoIf($[${KEY}=1]?continue:invalid)
 same => n(invalid),Set(ATTEMPT=$[${ATTEMPT}+1])
 same => n,EndWhile
 same => n,Playback(/usr/share/asterisk/sounds/custom/goodbye)
 same => n,Hangup()

 same => n(continue),Queue(all-phones,Cnr,,,30)
 same => n,Verbose(1,"Abandoned: ${ABANDONED}")
 same => n,Playback(/usr/share/asterisk/sounds/custom/associates-are-busy)
 same => n,GotoIf($[${ABANDONED}=TRUE]?Answering-Service,s,1)
 same => n,Hangup()

; DID Calls inbound
exten => _55500XX,1,Verbose(1,"Received call from ${CALLERID(num)} for DID ${EXTEN}")
 same => n,Goto(Internal,${EXTEN},1)
 same => n,Hangup()

[Closed]
exten => s,1,Verbose(1,"Call from ${CALLERID(num)} received after-hours")
 same => n,Playback(/usr/share/asterisk/sounds/custom/greeting-closed)
 same => n,Goto(Answering-Service,s,1)

[Answering-Service]
exten => s,1,Verbose(1,"Forward call from ${CALLERID(num)} to answering service")
 same => n,Set(CALLERID(name)=ACME INC)
 same => n,Set(CALLERID(num)=5551111)
 same => n,Playback(/usr/share/asterisk/sounds/custom/transfer-to-answering-service)
 same => n,Dial(PJSIP/answering-service@sip-trunk)
 same => n,Hangup()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.