IVR with PIN + API query

[off-hours-PIN]
;answer the call and set variables
exten => s,1,Answer(500)
exten => s,n,Set(IF_CORRECT=0)
exten => s,n,Set(RESULT=0)

;request a 6 digit PIN
exten => s,n,Read(PIN,custom/RequestPIN,6,n,1,10)
exten => s,n,Playback(you-entered)
exten => s,n,SayDigits(${PIN})
exten => s,n,Read(IF_CORRECT,custom/IfThisIsCorrect,1,n,1,3)
exten => s,n,GotoIf($[ ${IF_CORRECT} = 1 ]?CORRECT,1:HANGUP,1)

;send PIN to API using cURL
exten => CORRECT,1,Set(RESULT=${CURL(https://website/${PIN})})
exten => CORRECT,n,GotoIf($[ ${RESULT} = 1 ]?:HANGUP,1)
exten => CORRECT,n,Dial(SIP/[email protected])
exten => CORRECT,n,Goto(HANGUP,1)

;hangup the call
exten => HANGUP,1,Hangup()

2 Likes

If you want to try and keep a bit of this in the GUI for others, you can use a Misc Destination and Misc Application. It is certainly more cumbersome, but it keeps people out of config files if you need to change the number that is being dialled.

First, make a Misc Destination.
image

Then make a Misc Application that points to it.

Then have your context dial the Misc Application number

exten => CORRECT,n,(from-internal,4357,1)
1 Like

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