woah … way over-complicated
and you seem to be mixing up callee and caller. and i’m slightly confused as to why the callee needs to know what number was pressed if the options are e.g. 1 to leave VM, 0 to speak to operator. but anyway …
you can acheive this with a simple IVR like :
[inbound]
exten => s,1,Answer()
exten => s,2,Set(LOOPED=1)
exten => s,3,GotoIf($[${LOOPED} > 2]?hang,1)
exten => s,4,Set(TIMEOUT(digit)=3)
exten => s,5,Set(TIMEOUT(response)=7)
exten => s,6,Background(main-greeting)
exten => 0,1,Dial(SIP/100|30|A(caller-pressed-zero))
exten => 1,1,VoiceMail(100|ug(5))
exten => 2,1,VoiceMail(101|ug(5))
exten => 3,1,Dial(SIP/103|30|A(caller-pressed-three))
exten => 9,1,Goto(s,2); press 9 to repeat message
exten => h,1,Hangup()
exten => hang,1,Playback(vm-goodbye)
exten => hang,2,Hangup()
exten => i,1,Playback(invalid)
exten => i,2,Goto(s,2)
exten => t,1,Set(LOOPED=$[${LOOPED} + 1])
exten => t,2,Goto(s,3)
exten => o,1,Goto(s,2)
exten => a,1,Goto(hang,1)
you’ll need to record a few sound files that the Dial() statements 'A’nnounce before bridging.