;Version("3.1.2.134")
;InformationalVersion("3.1.2.0")

[nixxis-beep]

exten => beep,1,Answer

 same => n,Set(PROMPT=${SIP_HEADER(x-cr-prompt)})
 same => n,Set(ACCOUNTCODE=${SIP_HEADER(x-cr-acc)})

 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,GotoIf($["${PROMPT}" != "" ]?prompt)

 same => n,Playback(beep)
 same => n,HangUp()

 same => n(prompt),Playback(${PLAYDIR}/${PROMPT})
 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
