;Version("3.3.1255.138")
;InformationalVersion("3.3.1255.0")

[nixxis-monitoring]

exten => monitoring,1,NoOp(CallMonitor request)
 same => n,Set(CHANMON=${SIP_HEADER(x-cr-mon)})

 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(s,ParseIvrInfo(${RawAnswer}))

 same => n(ivrInfoDone),Answer()
 same => n,Playback(beep)
 same => n,ExecIf($["${SPYOPTIONS}" = ""]?Set(SpyOptions=${SIP_HEADER(x-cr-spyoptions)}))
 same => n,ExecIf($["${SPYOPTIONS}" = ""]?Set(SpyOptions=q))
 same => n,ChanSpy(${CHANMON},${SPYOPTIONS})

 same => n,HangUp()

exten => playback_recording,1,NoOp(Recording Playback requested)
 same => n,Set(ACCOUNTCODE=${SIP_HEADER(x-cr-acc)})
 same => n,Set(MONITORFILE=${SIP_HEADER(x-cr-rec)})

 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(s,ParseIvrInfo(${RawAnswer}))

 same => n(ivrInfoDone),ControlPlayback(${NixxisRecordingPath}/${ACCOUNTCODE}/${MONITORFILE})
 same => n,HangUp()

exten => s,1,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-mon"]?Set(CHANMON=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-act"]?Set(ACTIVITY=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-lan"]?Set(CHANNEL(language)=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-actlan"]?Set(CHANNEL(language)=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-rec"]?Set(MONITORFILE=${PartValue}))
 same => n,ExecIf($["${PartName}" = "x-cr-spyoptions"]?Set(SPYOPTIONS=${PartValue}))
 same => n,EndWhile
 same => n,Return
