; The "General" category is for certain variables.  
;
[general]
;
static=yes
writeprotect=yes

[globals]
; are we live production?
LIVE=1
; delays
WAIT_AFTER_ANSWER=2.7
BETWEEN_PROMPTS=1.7
MAX_MENU_LOOPS=0
; external CID number
OURCIDN=xxxxxxxxxx
OURCID="OUR CID NUM"
OURVOIP1=xxxxxxxxxx
; define local extensions
SpeakingClock=123
RecordVoice=_**6XX
ListenVoice=_**06XX
; real local extensions
SIP3040=3040
SIP3041=3041
SIP3042=3042
SIP3043=3043
SIP3044=3044
; groups, queues etc
SUPPORT_LIST=${SIP3042}

[macro-sipline]
exten => s,1,Dial(SIP/${ARG1},20,t)
exten => s,2,Voicemail(u${ARG1})
exten => s,3,playback(vm-goodbye) 
exten => s,4,wait(1)
exten => s,5,Hangup
exten => s,102,Voicemail(b${ARG1})
exten => s,103,playback(vm-goodbye) 
exten => s,104,wait(1)
exten => s,105,Hangup 

[macro-outvoip]
exten => s,1,SetCIDName(${OURCID}|a)
exten => s,2,SetCIDNum(${OURCIDN}|a)
exten => s,3,Dial(IAX2/voicepulse1/${ARG1})
exten => s,4,Congestion
exten => s,104,Dial(IAX2/voicepulse2/${ARG1})
exten => s,105,Congestion

[voicepulse-in]
exten => ${OURVOIP1},1,Noop(${DATETIME} ${CALLERID})
exten => ${OURVOIP1},2,Answer
exten => ${OURVOIP1},3,Goto(main-menu,s,6)
exten => ${OURVOIP1},4,Hangup

[incoming-sip]
include => voicepulse-in

exten => s,1,Noop(${DATETIME} ${CALLERID})
exten => s,2,Answer
exten => s,3,Goto(main-menu,s,6)
exten => s,4,Hangup

;;;; MAIN MENU ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[main-menu]
include => operator
include => queues

; if pressed 4-digit extension:
include => local

; for main menu selections:
exten => 1,1,Goto(office-day,1,1)
exten => 2,1,Goto(office-day,2,1)
exten => 3,1,Goto(office-day,3,1)
exten => 4,1,Goto(office-day,4,1)
exten => 5,1,Goto(office-day,5,1)

exten => s,1,Noop(${DATETIME} ${CALLERID})
exten => s,2,Answer
exten => s,3,Wait(${WAIT_AFTER_ANSWER})
exten => s,4,SetCallerID(${CALLERID})
exten => s,5,Wait(1)
exten => s,6,DigitTimeout,2
exten => s,7,ResponseTimeout,7
exten => s,8,Background(/usr/local/etc/asterisk/ivr/GREETING)
exten => s,9,WaitExten(1.2)
exten => s,10,SetGlobalVar(prompt_loops=0)
exten => s,11,GotoIfTime(07:00-18:00|mon-thu|*|*?office-day,s,2) 
exten => s,12,GotoIfTime(10:00-16:30|fri|*|*?office-day,s,2) 
exten => s,13,Goto(office-night,s,1)

exten => t,1,Goto(main-menu,#,1)          ; If they take too long, go to hangup

; invalid
exten => i,1,Wait(1)
exten => i,2,Playback(invalid)   ; "That's not valid, try again"
exten => i,3,Wait(1)
exten => i,4,Goto(s,6)

; #=hangup
exten => #,1,Wait(1)
exten => #,2,Playback(vm-goodbye)
exten => #,3,Wait(2)
exten => #,4,Hangup


[office-day]
include => operator
include => queues

; if pressed 3-digit extension:
include => local

; for accessing voicemail:
include => voicemail

exten => s,1,SetGlobalVar(prompt_loops=1)
exten => s,2,WaitExten(${BETWEEN_PROMPTS})
exten => s,3,Background(/usr/local/etc/asterisk/ivr/MAINMENU)
exten => s,4,WaitExten(4)
exten => s,5,SetGlobalVar(prompt_loops=$[${prompt_loops} + 1])
exten => s,6,GotoIf($[${prompt_loops} < ${MAX_MENU_LOOPS}] ? 2:23)
exten => s,7,Goto(operator,0,1)

; invalid
exten => i,1,Playback(invalid)   ; "That's not valid, try again"
exten => i,2,Wait(1)
exten => i,3,Goto(s,7)
; timeout
exten => t,1,Goto(operator,0,1)

[office-night]
include => operator
include => queues

; if pressed 3-digit extension:
include => local

; for accessing voicemail:
include => voicemail

exten => s,1,SetGlobalVar(prompt_loops=1)
exten => s,2,WaitExten(${BETWEEN_PROMPTS})
exten => s,3,Background(/usr/local/etc/asterisk/ivr/MAINMENU)
exten => s,4,WaitExten(4)
exten => s,5,SetGlobalVar(prompt_loops=$[${prompt_loops} + 1])
exten => s,6,GotoIf($[${prompt_loops} < ${MAX_MENU_LOOPS}] ? 2:23)
exten => s,7,Goto(operator,0,1)

; invalid
exten => i,1,Wait(1)
exten => i,2,Playback(invalid)   ; "That's not valid, try again"
exten => i,3,Wait(1)
exten => i,4,Goto(s,4)

; timeout
exten => t,1,Goto(main-menu,#,1)          ; If they take too long, go to hangup

[local]
; Speaking clock 
; Take a snapshot of the time - add 10 seconds (about the length of the anouncement) 
;  and use that as the basis of the time. 
exten => ${SpeakingClock},1,Wait(2) 
exten => ${SpeakingClock},2,setvar(FutureTime=$[${EPOCH} + 10]) 
exten => ${SpeakingClock},3,SayUnixTime(${FutureTime},,R) 
exten => ${SpeakingClock},4,playback(vm-and) 
exten => ${SpeakingClock},5,SayUnixTime(${FutureTime},,S) 
exten => ${SpeakingClock},6,playback(seconds) 
exten => ${SpeakingClock},7,playback(beep) 
exten => ${SpeakingClock},8,wait(2)
exten => ${SpeakingClock},9,DateTime 
exten => ${SpeakingClock},10,goto(1)

; Record voice file to /tmp directory
exten => ${RecordVoice},1,Wait(2) ; Call 600-699 to Record new Sound Files
exten => ${RecordVoice},2,Record(/tmp/${EXTEN:2}:wav) ; Press # to stop recording
exten => ${RecordVoice},3,Wait(2)
exten => ${RecordVoice},4,Playback(/tmp/${EXTEN:2}) ; Listen to your voice
exten => ${RecordVoice},5,wait(2)
exten => ${RecordVoice},6,Hangup
;;;;;
; Listen to voice file
exten => ${ListenVoice},1,Playback(/tmp/${EXTEN:3}) ; Listen to your voice
exten => ${ListenVoice},2,wait(4)
exten => ${ListenVoice},3,Hangup

; Directory:
exten => 411,1,Directory(crystal-sip|local)
exten => 411,2,Hangup

; ##### REAL LOCAL EXTENSIONS ###########################

exten => 3040,1,Macro(sipline,${SIP3040}) 
exten => 3041,1,Macro(sipline,${SIP3041}) 
exten => 3042,1,Macro(sipline,${SIP3042}) 
exten => 3043,1,Macro(sipline,${SIP3043}) 
exten => 3044,1,Macro(sipline,${SIP3044}) 

; invalid                                                                 
exten => i,1,Playback(invalid)   ; "That's not valid, try again" 
exten => i,2,Wait(1)                                                      
exten => i,3,Goto(0,2)                                                    

[agents]
exten => 1000,1,AgentCallbackLogin(|${CALLERIDNUM}@local)
exten => 1000,2,Hangup

exten => 1001,1,AgentCallbackLogin(1001|${CALLERIDNUM}@local)
exten => 1001,2,Hangup

exten => 1002,1,AgentCallbackLogin(1002|${CALLERIDNUM}@local)
exten => 1002,2,Hangup

exten => 1003,1,AgentCallbackLogin(1003|${CALLERIDNUM}@local)
exten => 1003,2,Hangup

exten => 1091,1,AgentCallbackLogin(1001)
exten => 1091,2,Hangup

exten => 1092,1,AgentCallbackLogin(1002)
exten => 1092,2,Hangup

exten => 1093,1,AgentCallbackLogin(1003)
exten => 1093,2,Hangup

[operator]
exten => 1,1,Background(queue-thankyou)
exten => 1,2,Dial(${SUPPORT_LIST}|30)
exten => 1,3,Goto(main-menu,5,1)

[queues]
; 2: support
exten => 2,1,Playback(queue-thankyou)
exten => 2,2,Queue(q_support|tT|||300) 
exten => 2,3,Playback(queue-thankyou) 
exten => 2,4,Voicemail(s1234)
; 3: cust.service
exten => 3,1,Playback(queue-thankyou)
exten => 3,2,Queue(q_custserv|tT|||300) 
exten => 3,3,Playback(queue-thankyou) 
exten => 3,4,Voicemail(s1234)
; 4: sales
exten => 4,1,Playback(queue-thankyou)
exten => 4,2,Queue(q_sales|tT|||300) 
exten => 4,3,Playback(queue-thankyou) 
exten => 4,4,Voicemail(s1234)
; 5: billing
exten => 5,1,Playback(queue-thankyou)
exten => 5,2,Queue(q_bill|tT|||300) 
exten => 5,3,Playback(queue-thankyou) 
exten => 5,4,Voicemail(s1234)
; 6: HR & press
exten => 6,1,Playback(queue-thankyou)
exten => 6,2,Queue(q_hrpr|tT|||300) 
exten => 6,3,Playback(queue-thankyou) 
exten => 6,4,Voicemail(s1234)
; 9: account system
exten => 9,1,Playback(queue-thankyou)
exten => 9,2,Queue(q_accsys|tT|||300) 
exten => 9,3,Playback(queue-thankyou) 
exten => 9,4,Voicemail(s1234)

[voip-outgoing]
exten => _91NXXNXXXXXX,1,Macro(outvoip,${EXTEN:1})
exten => _91NXXNXXXXXX,2,Congestion
exten => _9NXXNXXXXXX,1,Macro(outvoip,1${EXTEN:1})
exten => _9NXXNXXXXXX,2,Congestion

[voicemail]
; Define a way so that users can dial a number to reach
; voicemail. Call the VoicemailMain application with the
; number of the caller already passed as a variable, so
; all the user needs to do is type in the password.
exten => *9,1,Wait(1)
exten => *9,2,VoicemailMain(${CALLERIDNUM})
exten => *9,3,Hangup

; main voicemail (for phone users calling from outside)
exten => *99,1,Wait(1)
exten => *99,2,VoicemailMain
exten => *99,3,Hangup

[crystal-sip]

include => local

include => voicemail

include => agents

include => operator

include => queues

include => voip-outgoing
