;Version("3.3.1255.135")
;InformationalVersion("3.3.1255.0")

; $Id: hold-v2.conf 133 2011-12-15 14:19:35Z t.vanderkraan $
;
; Hold (and play sounds file) extension for V2
; 
; Usage: define hold extension within Nixxis Admin Tool
;
; Partner: -
; Client: -
; 
; Rev		: $Rev: 133 $
; Author	: $Author: t.vanderkraan $
; Date		: $Date: 2011-12-15 15:19:35 +0100 (jeu., 15 déc. 2011) $
;
; Initial Author: Tjardick van der Kraan <t.vanderkraan@nixxis.com>
;
; For support please contact: support@nixxis.com
;

[nixxis-hold-v2]
exten => hold-v2,1,NoOp(Getting a call to put on hold for activity ${SIP_HEADER(x-cr-act)})
 same => n,Set(ACTIVITY=${SIP_HEADER(x-cr-act)})
 same => n,Set(ACCOUNTCODE=${SIP_HEADER(x-cr-acc)})
 same => n,Set(LAN=${SIP_HEADER(x-cr-lan)})
 same => n,Set(MOH=${SIP_HEADER(x-cr-moh)})
 same => n,Set(PROMPT=${SIP_HEADER(x-cr-prompt)})

 same => n,GotoIf($["${SIP_HEADER(x-cr-iex)}" = "http"]?ivrInfoHttp:ivrInfoDone)

 same => n(ivrInfoHttp),Set(NixxisAppServerUri=${SIP_HEADER(x-cr-hsr)})
 same => n,Set(CURLOPT(httptimeout)=3)
 same => n,Set(RequestUri=${NixxisAppServerUri}/sip?action=getIvrInfo&sipid=${SIPCALLID}&version=${CUT(NixxisFileVersion,\",2)})
 same => n,Set(RawAnswer=${CURL(${RequestUri})})
 same => n,GoSub(ParseIvrInfo(${RawAnswer}))

 same => n(ivrInfoDone),Set(PLAYDIR=${NixxisSoundPath}/${ACCOUNTCODE})

 same => n,Answer
 same => n,Set(TIMEOUT(absolute)=14400)
 same => n,NoOp(Check if we have a prompt or just music)
 same => n,GotoIf($["${PROMPT}" != "" ]?prompt)
 same => n,NoOp(Check if we have a custom music class)
 same => n,GotoIf($["${MOH}" == "" ]?DefaultClass:SetClass)
 same => n(DefaultClass),Set(MOH=${ACTIVITY})
 same => n,GotoIf($["${MOH}" == "" ]?FallbackClass:SetClass)
 same => n(FallbackClass),Set(MOH=default)
 same => n(SetClass),Set(CHANNEL(musicclass)=${MOH})

 same => n(music),StartMusicOnHold
 same => n(loop),Wait(300)
 same => n,GoTo(loop)
 same => n(failed),Busy()
 same => n,Wait(5)
 same => n,HangUp()

 same => n(prompt),Playback(${PLAYDIR}/${PROMPT})
 same => n,NoOp(Done with Prompt sending END)
 same => n,Set(i=1)
 same => n,While($[${i} < 3])
 same => n,SendText(CRIVRend)
 same => n,Set(i=$[${i} + 1])
 same => n,Wait(1)
 same => n,EndWhile
 same => n,HangUp()

 same => n(ParseIvrInfo),NoOp(Parsing IvrInfo)
 same => n,While($["${SET(AnswerPart=${SHIFT(ARG1,&)})}" != ""])
 same => n,Set(PartName=${CUT(AnswerPart,=,1)})
 same => n,Set(PartValue=${CUT(AnswerPart,=,2)})
 same => n,ExecIf($["${PartName}" = "x-cr-acc"]?Set(ACCOUNTCODE=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-ani"]?Set(ANI=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-act"]?Set(ACTIVITY=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-lan"]?Set(LAN=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-moh"]?Set(MOH=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-prompt"]?Set(PROMPT=${PartValue}))
 same => n,EndWhile
 same => n,Return
