Hi,
This post is more to see if I am getting old and rusty with Asterisk.
I recently hired someone new and I am having him learn/experiment with Asterisk. I gave him this task
- Create a dialplan where a caller must press a randomly made up 3 digit pin.
- If they fail more than 3 times hangup.
- If they pass tell them good job and then play tt-monkeys.
Here is how I would do the code:
exten => 1234, 1, Answer()
same => n, Set(FAILCOUNT=0)
same => n, Set(PIN=${RAND(1,9)})
same =>n(enter-pin),Background(human-verify)
same => n, SayDigits(${PIN})
same => n, WaitExten(3)
same => n, Set(FAILCOUNT=$[${FAILCOUNT} + 1])
same => n, ExecIf($["${FAILCOUNT}" == "3"]?Hangup:Goto(enter-pin))
Exten => _X, 1,GotoIf($["${EXTEN}" == "${PIN}"]?success,1)
same => n, PlayBack(cheater)
same => n, goto(1234,enter-pin)
Exten => success, 1, PlayBack(yay)
He used AI to help along. Both suggested to use READ. Here is what Claude suggested
; Generate a random 3-digit PIN (100-999)
exten => s,1,Set(PIN=${RAND(100,999)})
same => n,Set(ATTEMPTS=0)
same => n,Goto(prompt-pin,1)
; Prompt for PIN entry
exten => prompt-pin,1,Set(ATTEMPTS=$[${ATTEMPTS}+1])
same => n,GotoIf($[${ATTEMPTS} > 3]?hangup-too-many-attempts,1)
same => n,Playback(please-enter-your)
same => n,SayNumber(3)
same => n,Playback(digit)
same => n,Playback(pin-number)
same => n,Read(USER_PIN,beep,3,,1,10)
same => n,GotoIf($["${USER_PIN}" = "${PIN}"]?success,1:incorrect-pin,1)
; Handle incorrect PIN
exten => incorrect-pin,1,Playback(invalid)
same => n,Playback(try-again)
same => n,Goto(prompt-pin,1)
; Handle successful PIN entry
exten => success,1,Playback(good-job)
same => n,Playback(tt-monkeys)
same => n,Hangup()
; Handle too many failed attempts
exten => hangup-too-many-attempts,1,Playback(im-sorry)
same => n,Playback(goodbye)
same => n,Hangup()
; Handle timeout or invalid input
exten => i,1,Playback(invalid)
same => n,Goto(prompt-pin,1)
exten => t,1,Playback(goodbye)
same => n,Hangup()
Is there a reason why AI saying to use Read and not use a “regular” dial plan? Am I “doing it wrong”?