IVR - Execute Shell Script / PHP file


(Lmon) #1

Hi,
I need to execute a shell script or a php file when I reach a specific step in my IVR workflow ( press 1 -> script1, press 2 -> script2 ) .
I found many posts on execution of external commands but giving solution around configuring manually some “dial plans”. ( ex here : Run external program after dialing special extension? or here : Running a Shell Script By Dialing Extension Number etc…)

How can I configure this into freePBX graphic interface ? some post are pretty old, so I assume there was update in the meantime ?
Thanks for your help


Being in an IVR, how I can "force" via an external action to move to another?
(Jerson Jr) #2

Every IVR created via web is saved in extensions_additional.conf, you can copy the code and take it to extensions_override_freepbx.conf with your custom code.
Do not forget that after that any change in the web would not have an effect on the flow of the IVR.


(Lmon) #3

Hi JersonJunior, thanks for answering.
I’ mnot sure to understand 100% what you are saying.
I have for example in the follwing code in my extention_additional.conf for IVR-1

[ivr-1] ; Bienvenue
include => ivr-1-custom
include => from-ivr-directory-Disabled
include => from-did-direct-ivr
exten => fax,1,Goto(${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)})

exten => s,1,Set(TIMEOUT_LOOPCOUNT=0)
exten => s,n,Set(INVALID_LOOPCOUNT=0)
exten => s,n,Set(IVR_CONTEXT${CONTEXT}=${IVR_CONTEXT})
exten => s,n,Set(_IVR_CONTEXT=${CONTEXT})
exten => s,n,Set(__IVR_RETVM=)
exten => s,n,GotoIf($["${CHANNEL(state)}" = “Up”]?skip)
exten => s,n,Answer
exten => s,n(skip),Set(IVR_MSG=custom/bienvenue)
exten => s,n(start),Set(TIMEOUT(digit)=3)
exten => s,n,ExecIf($["${IVR_MSG}" != “”]?Background(${IVR_MSG}))
exten => s,n,WaitExten(10,)

exten => 1,1,Set(__ivrreturn=0)
exten => 1,n(ivrsel-1),Goto(ivr-2,s,1)

exten => 2,1,Set(__ivrreturn=0)
exten => 2,n(ivrsel-2),Goto(app-blackhole,no-service,1)

exten => i,1,Set(INVALID_LOOPCOUNT=$[${INVALID_LOOPCOUNT}+1])
exten => i,n,GotoIf($[${INVALID_LOOPCOUNT} > 3]?final)
exten => i,n,Set(IVR_MSG=no-valid-responce-pls-try-again)
exten => i,n,Goto(s,start)
exten => i,n(final),Playback(no-valid-responce-transfering)
exten => i,n,Goto()

exten => t,1,Set(TIMEOUT_LOOPCOUNT=$[${TIMEOUT_LOOPCOUNT}+1])
exten => t,n,GotoIf($[${TIMEOUT_LOOPCOUNT} > 3]?final)
exten => t,n,Set(IVR_MSG=no-valid-responce-pls-try-again)
exten => t,n,Goto(s,start)
exten => t,n(final),Playback(no-valid-responce-transfering)
exten => t,n,Goto()

exten => return,1,Set(IVR_CONTEXT=${CONTEXT})
exten => return,n,Set(IVR_CONTEXT${CONTEXT}=${IVR_CONTEXT
${CONTEXT}})
exten => return,n,Set(IVR_MSG=custom/bienvenue)
exten => return,n,Goto(s,start)

exten => h,1,Hangup

exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup

;–== end of [ivr-1] ==–;

in short : 1 to go to next, 2 , to hang up

if I want to add 3, to run a shell script, I should add to extensions_override_freepbx.conf this ?

[…]

exten => 1,1,Set(__ivrreturn=0)
exten => 1,n(ivrsel-1),Goto(ivr-2,s,1)

exten => 2,1,Set(__ivrreturn=0)
exten => 2,n(ivrsel-2),Goto(app-blackhole,no-service,1)

exten => 3,1,System(/home/asterisk/my_script.sh)

exten => i,1,Set(INVALID_LOOPCOUNT=$[${INVALID_LOOPCOUNT}+1])
exten => i,n,GotoIf($[${INVALID_LOOPCOUNT} > 3]?final)
exten => i,n,Set(IVR_MSG=no-valid-responce-pls-try-again)
[…]

Thanks !


(Jerson Jr) #4

Yes, insert the code in extensions_overryde_freepbx.conf then dialplan reload on CLI


#5

There is no need to mess with with the IVR code. All you need do is put (or add) this in extensions_custom.conf:

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

Then, create a Custom Destination with Target
mycommand,s,1
and Description
domycommand

Set Return to Yes and Destination for what you want to happen after executing the command (play confirmation announcement, hangup the call, etc.)

Then in your IVR, set up option 3 with Destination of Custom Destinations domycommand.


(Lorne Gaetz) #6

+1 for @Stewart1’s post. You NEVER edit the override file unless there are zero other options.


(Lmon) #7

Hi,
The first method was working ( with extentsion_override.conf), Thanks.
I understand it is not the clean way to do it.
so , I recreated the step as Stewart1 explained
Everything works perfectly.
just one point to pay attention : enter the full path ( binaries, parameters …) in the shell script
Thanks to all !


(system) closed #8

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