;Version("3.1.2.2")
;InformationalVersion("3.1.2.0")

; $Id:$
;
; IVR dialplan used for the dutch 'bel me niet' blacklist.
; 
; Usage: define ivr extension within Nixxis Admin Tool
;
; Partner: -
; Client: -
; 
; Rev		: $Rev:$
; Author	: $Author:$
; Date		: $Date:$
;
; Initial Author: Tjardick van der Kraan <t.vanderkraan@nixxis.com>
;
; For support please contact: support@nixxis.com
;

[nixxis-belmeniet]

exten => s,1,NoOp(Getting a 'bel-me-niet' 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}/belmeniet)
same => n,Answer
same => n,Set(RequestUri=${APPSERVERURI}/blacklist?action=identity&contactid=${CONTACT})
same => n,Set(PHONENUMBER=${CURL(${RequestUri})})
same => n,Wait(2)
same => n,Set(TIMEOUT(absolute)=14400)
same => n,Set(INVALID=0)
same => n,GoTo(nixxis-belmeniet-intro,s,1)

[nixxis-belmeniet-intro]

exten => s,1,Background(${PLAYDIR}/ivr_intro)
exten => s,n,WaitExten(10)
exten => s,n,GoTo(nixxis-belmeniet-exit,s,1)

exten => 1,1,NoOp(Got: 2 - Exit)
exten => 1,n,GoTo(nixxis-belmeniet-menu,s,1)

exten => 2,1,NoOp(Got: 2 - Exit)
exten => 2,n,GoTo(nixxis-belmeniet-exit,s,1)

exten => i,1,NoOp(Invalid choice)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Set(INVALID=INVALID+1)
exten => i,n,GoTo(s,1)


[nixxis-belmeniet-menu]

exten => s,1,Background(${PLAYDIR}/ivr_hoofdkeuze)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-exit2,s,1)

exten => 1,1,NoOp(Got: 1 - submenu1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu1,s,1)

exten => 2,1,NoOp(Got: 2 - submenu2)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2,s,1)

exten => 3,1,NoOp(Got: 3 - submenu3)
exten => 3,n,GoTo(nixxis-belmeniet-submenu3,s,1)

exten => i,1,NoOp(Invalid choice)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,GoTo(s,1)

[nixxis-belmeniet-submenu1]

exten => s,1,NoOp(Performing local blacklist action)
same => n,NoOp(Preparing variables)
same => n,Set(PHONE=${PHONENUMBER})
same => n,Set(LEVEL=1)
same => n,NoOp(Performing blacklisting)
same => n,Set(RequestUri=${APPSERVERURI}/blacklist?action=add&number=${PHONE}&level=${LEVEL}&categories=${CATEGORIES}&description=${DESCRIPTION}&contactid=${CONTACT})
same => n,Set(Result=${CURL(${RequestUri})})
same => n,Background(${PLAYDIR}/ivr_afsluittekst_A)
same => n,WaitExten(5)
same => n,GoTo(nixxis-belmeniet-exit3,s,1)

exten => 1,1,NoOp(Got: 1 - back to menu)
exten => 1,n,GoTo(nixxis-belmeniet-menu,s,1)

exten => 2,1,NoOp(Got: 2 - exit)
exten => 2,n,GoTo(nixxis-belmeniet-drop,s,1)

exten => i,1,NoOp(Invalid choice)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,GoTo(s,1)


[nixxis-belmeniet-submenu2]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b1)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_AUTO=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-1,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_AUTO=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-1,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2,s,1)


[nixxis-belmeniet-submenu2-1]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b2)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-1,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_BOEKEN=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-2,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_BOEKEN=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-2,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-1,s,1)


[nixxis-belmeniet-submenu2-2]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b3)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-2,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_ENERGIE=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-3,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_ENERGIE=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-3,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-2,s,1)


[nixxis-belmeniet-submenu2-3]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b4)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-3,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_FINANCIEN=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-4,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_FINANCIEN=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-4,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-3,s,1)


[nixxis-belmeniet-submenu2-4]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b5)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-4,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_CHARIT=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-5,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_CHARIT=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-5,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-4,s,1)


[nixxis-belmeniet-submenu2-5]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b6)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-5,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_ESOTERIE=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-6,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_ESOTERIE=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-6,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-5,s,1)


[nixxis-belmeniet-submenu2-6]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b7)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-6,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_KRANTEN=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-7,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_KRANTEN=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-7,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-6,s,1)


[nixxis-belmeniet-submenu2-7]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b8)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-7,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_LOTERIJEN=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-8,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_LOTERIJEN=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-8,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-7,s,1)


[nixxis-belmeniet-submenu2-8]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b9)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-8,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_TELECOM=1)
exten => 1,n,GoTo(nixxis-belmeniet-submenu2-9,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_TELECOM=0)
exten => 2,n,GoTo(nixxis-belmeniet-submenu2-9,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-8,s,1)


[nixxis-belmeniet-submenu2-9]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_b10)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-submenu2-9,s,1)

exten => 1,1,NoOp(Got: 1 - block)
exten => 1,n,Set(BLK_POSTORDER=1)
exten => 1,n,GoTo(nixxis-belmeniet-registration,s,1)

exten => 2,1,NoOp(Got: 2 - unblock)
exten => 2,n,Set(BLK_POSTORDER=0)
exten => 2,n,GoTo(nixxis-belmeniet-registration,s,1)

exten => i,1,NoOp(Invalid)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,Goto(nixxis-belmeniet-submenu2-9,s,1)


[nixxis-belmeniet-submenu3]

exten => s,1,Background(${PLAYDIR}/ivr_afsluittekst_c)
exten => s,n,WaitExten(5)
exten => s,n,GoTo(nixxis-belmeniet-exit2,s,1)

exten => 1,1,NoOp(Got: 1 - subchoice)
exten => 1,n,Set(BLK_AUTO=1)
exten => 1,n,Set(BLK_BOEKEN=1)
exten => 1,n,Set(BLK_ENERGIE=1)
exten => 1,n,Set(BLK_FINANCIEN=1)
exten => 1,n,Set(BLK_ESOTERIE=1)
exten => 1,n,Set(BLK_KRANTEN=1)
exten => 1,n,Set(BLK_LOTERIJEN=1)
exten => 1,n,Set(BLK_TELECOM=1)
exten => 1,n,Set(BLK_POSTORDER=1)
exten => 1,n,GoTo(nixxis-belmeniet-subchoice1,s,1)

exten => 2,1,NoOp(Got: 2 - exit)
exten => 2,n,GoTo(nixxis-belmeniet-menu,s,1)

exten => i,1,NoOp(Invalid choice)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,GoTo(s,1)

[nixxis-belmeniet-subchoice1]

exten => s,1,Background(${PLAYDIR}/ivr_subkeuze_1)
exten => s,n,WaitExten(5)
exten => s,n,Set(IVR_SUBCHOICE=1)
exten => s,n,GoTo(nixxis-belmeniet-exit2,s,1)

exten => 1,1,NoOp(Got: 1 - back to menu)
exten => 1,n,Set(BLK_CHARIT=0)
exten => 1,n,GoTo(nixxis-belmeniet-registration,s,1)

exten => 2,1,NoOp(Got: 2 - exit)
exten => 2,n,Set(BLK_CHARIT=1)
exten => 2,n,GoTo(nixxis-belmeniet-registration,s,1)

exten => i,1,NoOp(Invalid choice)
exten => i,n,Playback(${PLAYDIR}/ivr_geen_juiste_ingave)
exten => i,n,GoTo(s,1)

[nixxis-belmeniet-registration]

exten => s,1,Playback(${PLAYDIR}/ivr_registratie_1)
exten => s,n,SayDigits(${PHONENUMBER})
exten => s,n,Goto(nixxis-belmeniet-registration2,s,1)


[nixxis-belmeniet-registration2]

exten => s,1,NoOp(Get Postalcode)
exten => s,n,Read(POSTALCODE,${PLAYDIR}/ivr_registratie_2)
exten => s,n,Goto(nixxis-belmeniet-registration3,s,1)

[nixxis-belmeniet-registration3]

exten => s,1,NoOp(Get house number)
exten => s,n,Read(HOUSENUMBER,${PLAYDIR}/ivr_registratie_3)
exten => s,n,Goto(nixxis-belmeniet-exit2,s,1)


[nixxis-belmeniet-exit]
exten => s,1,Background(${PLAYDIR}/ivr_exit)
exten => s,n,Wait(3)
exten => s,n,GoTo(nixxis-belmeniet-drop,s,1)


[nixxis-belmeniet-exit2]
exten => s,1,NoOp(Preparing variables)
same => n,Set(PHONE=${PHONENUMBER})
same => n,Set(LEVEL=2)
same => n,Set(CATEGORIES=${BLK_AUTO}${BLK_BOEKEN}${BLK_ENERGIE}${BLK_FINANCIEN}${BLK_CHARIT}${BLK_ESOTERIE}${BLK_KRANTEN}${BLK_LOTERIJEN}${BLK_TELECOM}${BLK_POSTORDER})
same => n,Set(DESCRIPTION=${POSTALCODE}_${HOUSENUMBER})
same => n,NoOp(Performing blacklisting)
same => n,Set(RequestUri=${APPSERVERURI}/blacklist?action=add&number=${PHONE}&level=${LEVEL}&categories=${CATEGORIES}&description=${DESCRIPTION}&contactid=${CONTACT})
same => n,Set(Result=${CURL(${RequestUri})})
same => n,Playback(${PLAYDIR}/ivr_exit_2)
same => n,Wait(3)
same => n,GoTo(nixxis-belmeniet-drop,s,1)

[nixxis-belmeniet-exit3]
exten => s,1,Background(${PLAYDIR}/ivr_exit_3)
exten => s,n,Wait(3)
exten => s,n,GoTo(nixxis-belmeniet-drop,s,1)

[nixxis-belmeniet-drop]

exten => s,1,NoOp(Done with IVR sending END)
exten => s,n,Set(i=1)
exten => s,n,While($[${i} < 3])
exten => s,n,SendText(${IVRCHOICES}\,CRIVRdrop\,CRIVRend)
exten => s,n,Set(i=$[${i} + 1])
exten => s,n,Wait(5)
exten => s,n,EndWhile
exten => s,n,HangUp()



