In future, please at least post a sample of the code you've tried so that we can see what you're trying to do. It helps us understand your objectives.
That said, give this a try. Please understand this is untested code I pretty much wrote while having my morning coffee. You will need to alter it to suit your needs / make it work.
I am being pedantic with the way I formatted the "Read" command, but the idea is for you to understand how this is set up. I actually tend to write my production code this way, simply so that it is closer to "self documenting".
[auto_attendant]
exten => _0030XXXXXXXX,1, Verbose(2, -- New Call For Auto-Attendant)
same => n, Verbose(2, --- configuring environment)
same => n, Set(my_aa_PromptFile=my_auto_attendant_greeting)
same => n, Set(my_aa_MaxDigits=4)
same => n, Set(my_aa_Options=s)
same => n, Set(my_aa_Attempts=1)
same => n, Set(my_aa_TimeOut=6)
same => n, Set(my_aa_MaxExtension=2003)
same => n, Set(my_aa_CountStrikes=0)
same => n, Verbose(2, --- handling call)
same => n, Answer()
same => n, Playback(silence/1)
same => n(try_again), Read(var_DTMF,${my_aa_PromptFile},${my_aa_MaxDigits},${my_aa_Options},${my_aa_Attempts},${my_aa_TimeOut})
same => n, GotoIf($["${var_DTMF}" = ""]?handle_error)
same => n, GotoIf($[${var_DTMF} > ${my_aa_MaxExtension}]?handle_error)
same => n, Dial(SIP/${var_DTMF},22)
same => n, Goto(try_again)
same => n(handle_error), Verbose(2, --- error condition)
same => n, Playback(my_auto_attendant_invalid_response)
same => n, Set(my_aa_CountStrikes=$[${my_aa_CountStrikes} + 1])
same => n, GotoIf($[${my_aa_CountStrikes} < 4 ]?try_again)
same => n, Playback(my_auto_attendant_please_try_again_later)
same => n, Hangup()
Further Reading:
Please Note:
if this answer turns out to solve your problem, please "accept" it for the benefit of others trying to solve the same problem later