; ############################################################################
; Applications [app]
; ############################################################################
;
[app-directory]
;DIR-CONTEXT set in Digital Receptionist
exten => ${APP-DIRECTORY},1,Wait(1)
exten => ${APP-DIRECTORY},2,AGI(directory,${DIR-CONTEXT},ext-local,${DIRECTORY:0:1}${DIRECTORY_OPTS}o)
exten => ${APP-DIRECTORY},3,Playback(vm-goodbye)
exten => ${APP-DIRECTORY},4,Hangup
; ${APP-DIRECTORY-TOTAL} will access the entire directory (not just a single context)
exten => ${APP-DIRECTORY-TOTAL},1,Answer
exten => ${APP-DIRECTORY-TOTAL},2,Wait(1)
exten => ${APP-DIRECTORY-TOTAL},3,AGI(directory,general,ext-local,${DIRECTORY:0:1}${DIRECTORY_OPTS})
exten => ${APP-DIRECTORY-TOTAL},4,Playback(vm-goodbye)
exten => ${APP-DIRECTORY-TOTAL},5,Hangup
exten => h,1,Hangup
exten => o,1,GotoIf($["foo${FROM_DID}" = "foo"]?from-pstn,s,1:from-pstn,${FROM_DID},1)

[app-dnd]
exten => ${APP-DND-ON},1,Answer
exten => ${APP-DND-ON},2,Wait(1)
exten => ${APP-DND-ON},3,Macro(user-callerid)
exten => ${APP-DND-ON},4,Set(DB(DND/${CALLERID(number)})=YES)
exten => ${APP-DND-ON},5,Playback(do-not-disturb)
exten => ${APP-DND-ON},6,Playback(activated)
exten => ${APP-DND-ON},7,Macro(hangupcall)
exten => ${APP-DND-OFF},1,Answer
exten => ${APP-DND-OFF},2,Wait(1)
exten => ${APP-DND-OFF},3,Macro(user-callerid)
exten => ${APP-DND-OFF},4,DBdel(DND/${CALLERID(number)})
exten => ${APP-DND-OFF},5,Playback(do-not-disturb)
exten => ${APP-DND-OFF},6,Playback(de-activated)
exten => ${APP-DND-OFF},7,Macro(hangupcall)

[app-messagecenter]
exten => ${APP-MESSAGECENTER},1,Answer
exten => ${APP-MESSAGECENTER},2,Wait(1)
exten => ${APP-MESSAGECENTER},3,Macro(user-callerid)
exten => ${APP-MESSAGECENTER},4,Macro(get-vmcontext,${CALLERIDNUM})
; Asterisk 1.2 _requires_ that context be set if mailbox is not in default context
; Dialing ${APP-MESSAGECENTER} from an IVR will be a problem, as macro-get-vmcontext will only return "default" in that case
exten => ${APP-MESSAGECENTER},5,VoiceMailMain(${VMCONTEXT})
exten => ${APP-MESSAGECENTER},6,Macro(hangupcall)
exten => _${APP-MESSAGECENTER}X.,1,Answer                      ; can dial ${APP-MESSAGECENTER}<exten> to skip 'mailbox' prompt.  Useful for speedial.
exten => _${APP-MESSAGECENTER}X.,2,Wait(1)
exten => _${APP-MESSAGECENTER}X.,3,Macro(get-vmcontext,${EXTEN:3})
exten => _${APP-MESSAGECENTER}X.,4,VoiceMailMain(${EXTEN:3}@${VMCONTEXT})
exten => _${APP-MESSAGECENTER}X.,5,Macro(hangupcall)
exten => ${APP-MESSAGECENTER-DIRECT},1,Answer
exten => ${APP-MESSAGECENTER-DIRECT},2,Wait(1)
exten => ${APP-MESSAGECENTER-DIRECT},3,Macro(user-callerid)
exten => ${APP-MESSAGECENTER-DIRECT},4,Macro(get-vmcontext,${CALLERIDNUM})
exten => ${APP-MESSAGECENTER-DIRECT},5,VoicemailMain(${CALLERIDNUM}@${VMCONTEXT})
exten => ${APP-MESSAGECENTER-DIRECT},6,Macro(hangupcall)

[app-callwaiting]
exten => ${APP-CALLWAITING-ON},1,Answer
exten => ${APP-CALLWAITING-ON},2,Wait(1)
exten => ${APP-CALLWAITING-ON},3,Macro(user-callerid)
exten => ${APP-CALLWAITING-ON},4,Set(DB(CW/${CALLERID(number)})=ENABLED)
exten => ${APP-CALLWAITING-ON},5,Playback(call-waiting)
exten => ${APP-CALLWAITING-ON},6,Playback(activated)
exten => ${APP-CALLWAITING-ON},7,Macro(hangupcall)
exten => ${APP-CALLWAITING-OFF},1,Answer
exten => ${APP-CALLWAITING-OFF},2,Wait(1)
exten => ${APP-CALLWAITING-OFF},3,Macro(user-callerid)
exten => ${APP-CALLWAITING-OFF},4,DBdel(CW/${CALLERID(number)})
exten => ${APP-CALLWAITING-OFF},5,Playback(call-waiting)
exten => ${APP-CALLWAITING-OFF},6,Playback(de-activated)
exten => ${APP-CALLWAITING-OFF},7,Macro(hangupcall)

[app-callforward]
; dialed call forward app - forwards calling extension
exten => _${APP-CALLFORWARD-ON}.,1,Macro(user-callerid)
exten => _${APP-CALLFORWARD-ON}.,2,Set(DB(CF/${CALLERID(number)})=${EXTEN:3})
exten => _${APP-CALLFORWARD-ON}.,3,Answer
exten => _${APP-CALLFORWARD-ON}.,4,Wait(1)
exten => _${APP-CALLFORWARD-ON}.,5,Playback(call-fwd-unconditional)
exten => _${APP-CALLFORWARD-ON}.,6,Playback(for)
exten => _${APP-CALLFORWARD-ON}.,7,Playback(extension)
exten => _${APP-CALLFORWARD-ON}.,8,SayDigits(${CALLERID(number)})
exten => _${APP-CALLFORWARD-ON}.,9,Playback(is-set-to)
exten => _${APP-CALLFORWARD-ON}.,10,SayDigits(${EXTEN:3})
exten => _${APP-CALLFORWARD-ON}.,11,Macro(hangupcall)
; prompting call forward app - forwards entered extension
exten => ${APP-CALLFORWARD-ON},1,Answer
exten => ${APP-CALLFORWARD-ON},2,Wait(1)
exten => ${APP-CALLFORWARD-ON},3,BackGround(please-enter-your)
exten => ${APP-CALLFORWARD-ON},4,Playback(extension)
exten => ${APP-CALLFORWARD-ON},5,Read(fromext,then-press-pound)
exten => ${APP-CALLFORWARD-ON},6,Wait(1)
exten => ${APP-CALLFORWARD-ON},7,BackGround(ent-target-attendant)
exten => ${APP-CALLFORWARD-ON},8,Read(toext,then-press-pound)
exten => ${APP-CALLFORWARD-ON},9,Wait(1)
exten => ${APP-CALLFORWARD-ON},10,Set(DB(CF/${fromext})=${toext})
exten => ${APP-CALLFORWARD-ON},11,Playback(call-fwd-unconditional)
exten => ${APP-CALLFORWARD-ON},12,Playback(for)
exten => ${APP-CALLFORWARD-ON},13,Playback(extension)
exten => ${APP-CALLFORWARD-ON},14,SayDigits(${fromext})
exten => ${APP-CALLFORWARD-ON},15,Playback(is-set-to)
exten => ${APP-CALLFORWARD-ON},16,SayDigits(${toext})
exten => ${APP-CALLFORWARD-ON},17,Macro(hangupcall)
; cancels dialed extension call forward
exten => _${APP-CALLFORWARD-OFF}.,1,DBdel(CF/${EXTEN:3})
exten => _${APP-CALLFORWARD-OFF}.,2,Answer
exten => _${APP-CALLFORWARD-OFF}.,3,Wait(1)
exten => _${APP-CALLFORWARD-OFF}.,4,SayDigits(${EXTEN:3})
exten => _${APP-CALLFORWARD-OFF}.,5,Playback(call-fwd-cancelled)
exten => _${APP-CALLFORWARD-OFF}.,6,Macro(hangupcall)
; cancels call forward for calling extension
exten => ${APP-CALLFORWARD-OFF},1,Macro(user-callerid)
exten => ${APP-CALLFORWARD-OFF},2,DBdel(CF/${CALLERID(number)})
exten => ${APP-CALLFORWARD-OFF},3,Answer
exten => ${APP-CALLFORWARD-OFF},4,Wait(1)
exten => ${APP-CALLFORWARD-OFF},5,Playback(call-fwd-cancelled)
exten => ${APP-CALLFORWARD-OFF},6,Macro(hangupcall)
; dialed call forward on busy app - forwards calling extension when busy
exten => _${APP-CALLFORWARD-BUSY-ON}.,1,Macro(user-callerid)
exten => _${APP-CALLFORWARD-BUSY-ON}.,2,Set(DB(CFB/${CALLERID(number)})=${EXTEN:3})
exten => _${APP-CALLFORWARD-BUSY-ON}.,3,Answer
exten => _${APP-CALLFORWARD-BUSY-ON}.,4,Wait(1)
exten => _${APP-CALLFORWARD-BUSY-ON}.,5,Playback(call-fwd-on-busy)
exten => _${APP-CALLFORWARD-BUSY-ON}.,6,Playback(for)
exten => _${APP-CALLFORWARD-BUSY-ON}.,7,Playback(extension)
exten => _${APP-CALLFORWARD-BUSY-ON}.,8,SayDigits(${CALLERID(number)})
exten => _${APP-CALLFORWARD-BUSY-ON}.,9,Playback(is-set-to)
exten => _${APP-CALLFORWARD-BUSY-ON}.,10,SayDigits(${EXTEN:3})
exten => _${APP-CALLFORWARD-BUSY-ON}.,11,Macro(hangupcall)
; cancels call forward on busy for calling extension
exten => ${APP-CALLFORWARD-BUSY-OFF},1,Macro(user-callerid)
exten => ${APP-CALLFORWARD-BUSY-OFF},2,DBdel(CFB/${CALLERID(number)})
exten => ${APP-CALLFORWARD-BUSY-OFF},3,Answer
exten => ${APP-CALLFORWARD-BUSY-OFF},4,Wait(1)
exten => ${APP-CALLFORWARD-BUSY-OFF},5,Playback(call-fwd-on-busy)
exten => ${APP-CALLFORWARD-BUSY-OFF},6,Playback(de-activated)
exten => ${APP-CALLFORWARD-BUSY-OFF},7,Macro(hangupcall)
exten => h,1,Hangup

[app-calltrace]
; We can't have our timeouts or dial digits collide with other applications
; or extensions, so we build the app in pieces
exten => ${APP-CALLTRACE},1,Goto(app-calltrace-perform,s,1)

[app-calltrace-perform]
exten => s,1,Macro(user-callerid)
exten => s,2,Answer
exten => s,3,Wait(1)
exten => s,4,Background(info-about-last-call)
exten => s,5,Background(telephone-number)
exten => s,6,Set(lastcaller=${DB(CALLTRACE/${CALLERID(number)})})
exten => s,7,GotoIf($[${lastcaller}]?8:14)
exten => s,8,SayDigits(${lastcaller})
exten => s,9,Set(TIMEOUT(digit)=3)
exten => s,10,Set(TIMEOUT(response)=7)
exten => s,11,Background(to-call-this-number)
exten => s,12,Background(press-1)
exten => s,13,Goto(16)
exten => s,14,Playback(from-unknown-caller)
exten => s,15,Macro(hangupcall)
exten => s,16,NoOp
exten => 1,1,Goto(from-internal,${lastcaller},1);
exten => i,1,Playback(vm-goodbye)
exten => i,2,Macro(hangupcall)
exten => t,1,Playback(vm-goodbye)
exten => t,2,Macro(hangupcall)

[app-userlogonoff]
exten => ${APP-USERLOGON},1,Macro(user-logon)
exten => ${APP-USERLOGON},2,Hangup()
exten => _${APP-USERLOGON}.,1,Macro(user-logon,${EXTEN:3})
exten => _${APP-USERLOGON}.,2,Hangup()
exten => ${APP-USERLOGOFF},1,Macro(user-logoff)
exten => ${APP-USERLOGOFF},2,Hangup()

