Random IVR code

Lazy Saturday and it’s too wet to rake leaves.

  • create a Custom Destination with a goto string of bender-blocker,s,1
  • choose the Return option and set the destination to where ever you want legit calls to go
  • route calls through an Announcement saying something like “please enter the following digits”
  • then route to the Custom Destination.
  • add the following lines to the file /etc/asterisk/extensions_custom.conf
[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)}${RAND(0,9)}${RAND(0,9)}${RAND(0,9)}) ; generates a 4 digit number, modify as req'd
exten => s,n,SayDigits(${goal})
exten => s,n,Read(dtmf-in,,${LEN(${goal})},,,10)   ; 10 second timeout, modify as req'd
exten => s,n,execif($["${dtmf-in}"="${goal}"]?Return)      ;  if input matches, send back to FreePBX 

; give caller multiple chances
exten => s,n,Set(Count=$[${Count}+1])
exten => s,n,gotoif($["${Count}"="3"]?finish)   ; bail after 3rd attempt
exten => s,n,Playback(challenge_try_again)      ; sub your own recording
exten => s,n,goto(restart)

; what do you want to do with calls that fail?
exten => s,n(finish),hangup

3 Likes