;Version("3.3.1255.2")
;InformationalVersion("3.3.1255.0")

[nixxis-opt-out]

exten => s,1,NoOp(Getting a 'opt-out' IVR call)
same => n,NoOp(HSR header: ${SIP_HEADER(x-cr-act)})
same => n,Set(ACTIVITY=${SIP_HEADER(x-cr-act)})
same => n,Set(CONTACT=${SIP_HEADER(x-cr-con)})
same => n,Set(APPSERVERURI=${SIP_HEADER(x-cr-hsr)})
same => n,Set(ACCOUNTCODE=${SIP_HEADER(x-cr-acc)})
same => n,Set(PLAYDIR=${NixxisSoundPath}/${ACCOUNTCODE}/opt-out)
same => n,Answer
same => n,GoTo(nixxis-opt-out-intro,s,1)

[nixxis-opt-out-intro]
exten => s,1(intro),Background(${PLAYDIR}/ivr_intro)
same => n,WaitExten(10)

exten => 1,1,NoOp(Got: 1 - Opt-out request)
same => n,Set(RequestUri=${APPSERVERURI}/blacklist?action=add&activityid=${ACTIVITY}&contactid=${CONTACT}&level=1&description=ivr)
same => n,Set(RawAnswer=${CURL(${RequestUri})})
same => n, GoTo(nixxis-opt-out-end,s,1)

exten => i,1,NoOp(Invalid choice)
same => n,GoTo(nixxis-opt-out-intro,s,1)



[nixxis-opt-out-end]
exten => s,1,NoOp(Done with IVR sending END)
same => n,Background(${PLAYDIR}/ivr_outtro)
same => n,Set(i=1)
same => n,While($[${i} < 3])
same => n,SendText(${IVRCHOICES}\,CRIVRdrop\,CRIVRend)
same => n,Set(i=$[${i} + 1])
same => n,Wait(5)
same => n,EndWhile
same => n,HangUp()



