;Version("3.3.1255.134")
;InformationalVersion("3.3.1255.0")

[nixxis-customer-identification]

exten => s,1,Answer()
same  => n,Set(CHANNEL(language)=${SIP_HEADER(x-cr-actlan)})
same  => n,Wait(2)
same  => n(enteruser),Read(AUTHUSER,agent-user)
same  => n,Set(RequestUri=http://${SIP_HEADER(x-cr-hsr)}/data?action=listMatchingData&returnfields=internal__id__&___CustomerId=${AUTHUSER}&activity=${SIP_HEADER(x-cr-act)})
same  => n,Set(AUTHRESULT=${CURL(${RequestUri})})

same  => n,NoOp( Auth result : ${AUTHRESULT} - ${LEN(${AUTHRESULT})} )
same  => n,GotoIf($[${LEN(${AUTHRESULT})} > 1]?loginok)
same  => n,Playback(login-fail)
same  => n,Goto(enteruser)
same  => n(loginok),NoOp( Login OK)
same  => n,Set(RequestUri=http://${SIP_HEADER(x-cr-hsr)}/data?action=setinternalid&id=${CUT(CUT(AUTHRESULT,>,4),<,1)}&contact=${SIP_HEADER(x-cr-con)})
same  => n,Set(AUTHRESULT=${CURL(${RequestUri})})

same  => n,GoTo(nixxis-ivr-v2-end,s,1)
