Revisting IVR -> Script


(W0OTM) #1

This topic has been discussed before: ivr-execute-shell-script-php-file/59726

I am wanting to pass the CALLERID and IVR option chosen as a variable to the shell script. (I plan to have the shell script execute a wget to a remote url/php file.
example:
my_script.sh
wget xxxx://server.com/newcaller.php?callerid=XXXXXXXXX&option=2

[mycommand]
exten => s,1,System(/home/asterisk/my_script.sh,$CALLERID,$IVROPTION)
exten => s,n,Return

Am I on the right track? What would be the variable names for CALLERID and IVR Options?


(Itzik) #2

CallerID Variables are documented here https://wiki.asterisk.org/wiki/display/AST/Asterisk+Standard+Channel+Variables

So you would want something like ${CALLERID(num)} or ${CALLERID(all)}

AFAIK $IVROPTION is not a variable, but could be I am wrong.

You have two options:

First. Point each IVR option to a custom destination which will execute a custom dilaplan and then set the return to your final destination.

Second. Do something like as mentioned here:
https://community.freepbx.org/t/ivr-entries-report/72010/14?u=pitzkey

In the override file:

[ivr-3]
exten => 1,1,Gosub(ivr-track,s,1(${EXTEN}))
exten => 2,1,Gosub(ivr-track,s,1(${EXTEN}))
exten => 3,1,Gosub(ivr-track,s,1(${EXTEN}))
exten => 4,1,Gosub(ivr-track,s,1(${EXTEN}))

And in extensions_custom.conf

[ivr-track]
exten => s,1,Noop(Entering context in extensions_custom.conf to execute custom dialplan)
exten => s,n,TrySystem(/home/asterisk/my_script.sh ${CALLERID(num)} ${ARG1})
exten => s,n,Set(__ivrreturn=0)
exten => s,n,Return()

Hope that helps


(Ian Plain) #3

If all your script is doing is calling a PHP script, I would call that direct from the dialplan using CURL and that way you can get some type of response back as to success or failed for the command similar as to below that we use for opening and shutting a gate

same = n,Set(foo=${CURL(http://gatephone:80/api/switch/ctrl?switch=2&action=off&response=relay2_off)})