Captcha IVR Help

Hi All,
Trying to modify a great script created awhile ago by community member lgaetz (I cant post a link to the post since I’m a new user, sorry!) to prevent spam and robocallers.

Brand new to custom Asterisk dialplans, so I apologize in advance if the code is messy. I’m having issues trying to conceptualize how to manipulate/read one of the variables generated by a random generator to control the call flow. Here’s what I have so far:

[bender-blocker]
exten => s,1,Noop(Entering context bender-blocker in extensions_custom.conf)
exten => s,n,Answer
exten => s,n,Set(count=0)
exten => s,n(restart),Set(goal=${RAND(0,9)}) ; generates a random number, modify as req'd

exten => s,n,ExecIf($["${goal}"="1"]?SayDigits(1)) ; will assign discrete Playback() files later that I recorded
exten => s,n,ExecIf($["${goal}"="2"]?SayDigits(2))
exten => s,n,ExecIf($["${goal}"="3"]?SayDigits(3))
exten => s,n,ExecIf($["${goal}"="4"]?SayDigits(4))
exten => s,n,ExecIf($["${goal}"="5"]?SayDigits(5))
exten => s,n,ExecIf($["${goal}"="6"]?SayDigits(6))
exten => s,n,ExecIf($["${goal}"="7"]?SayDigits(7))
exten => s,n,ExecIf($["${goal}"="8"]?SayDigits(8))
exten => s,n,ExecIf($["${goal}"="9"]?SayDigits(9))
exten => s,n,ExecIf($["${goal}"="0"]?SayDigits(0))

exten => WaitExten()

exten => ${goal},n,Return ; conceptually would like to use ${goal} variable to control which is a valid extension and return it to the FPBX call flow

exten => i,1,Playback(invalid_option)
exten => i,n,Goto(restart)

exten => t,1,Playback(goodbye)
exten => t,n,Hangup()

I am using the WaitExten() application to handle timeouts and if the caller were to press digits while a recording is being played.

Thanks in advance!

Welcome to the community Chris, sharing links available you now.

First I will say, while doing these types of projects is fun, in my experience spam calls are pretty much all robots, so can be stopped by a simple IVR.

Comments on your dialplan:

  • WaitExten line is malformed, it will just stop execution there
exten => s,n,WaitExten()
  • The individual ExecIf lines are unnecessary unless you have future plans to interact with the caller differently depending on the value of ${goal}, they can all be replaced with:
exten => s,n,SayDigits(${goal}))
  • You can’t use a variable for a dialplan exten like you have, you will need something like this:
exten => _X,1,execif($["${EXTEN}"="${goal}"]?Return)
exten => _X,n,goto(bender-blocker,s,restart)

Once you have this working, you will want to use it in conjunction with the Allow List module so you don’t challenge known callers.

Figured it out! Thanks so much for the _X extension - that did the trick. For anyone interested, here is the code I currently have working:

[bender-blocker]
exten => s,1,Noop(Entering context bender-blocker in extensions_custom.conf)
exten => s,n,Answer
exten => s,n,Set(Count=0)
exten => s,n(restart),Set(goal=${RAND(0,9)}) ; generates a random number, modify as req'd
exten => s,n,GotoIf($["${Count}"="3"]?bender-blocker,123,1)   ; bail after 3rd attempt

;  will assign discrete Playback() files later that I recorded
; exten => s,n,ExecIf($["${goal}"="1"]?Background())

exten => s,n,SayDigits(${goal})
exten => s,n,WaitExten()

; valid press handler
exten => _X,1,ExecIf($["${EXTEN}"="${goal}"]?Return)

; invalid press handler
exten => i,1,Playback(badinput)
exten => i,n,Set(Count=$[${Count}+1])
exten => i,n,Goto(bender-blocker,s,restart)

; timeout handler
exten => t,1,Playback(noinput)
exten => t,n,Set(Count=$[${Count}+1])
exten => t,n,Goto(bender-blocker,s,restart)

; what do you want to do with calls that fail?
exten => 123,1,Playback(goodbye)
exten => 123,n,Hangup()

Wondering now, if its not too complicated, to have WaitExten handle multiple digits? In the original code I believe you had it generate a 4 digit PIN. Either that or if the user would have the ability to press # or * at the end of the prompt to terminate input.

That’s what the original dialplan does. You can modify the line that sets the goal to however many digits you want.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.