Difference between revisions of "Passing DTMF to shell scripts"

From AllStarLink Wiki
Jump to navigation Jump to search
Line 64: Line 64:
  
  
==Useful Example Scripts/DialPlans:==
+
==Example Scripts/DialPlans using this method:==
  
 
Record system message/ID's - https://wiki.allstarlink.org/wiki/Recording_Audio_Files
 
Record system message/ID's - https://wiki.allstarlink.org/wiki/Recording_Audio_Files

Revision as of 21:45, 4 December 2022

This is at least one method to pass DTMF 'strings' to a shell script to be evaluated and executed accordingly.

It is basically a workaround, as it is not normally possible in the app_rpt/ASL functionality in the 'radio' channel.

We start with an extra command for a phone patch using a different command execution number and a different asterisk 'context' and a few other settings that would be different from what we would need to use 'autopatch function'. These settings make it quite and seamless.

So if you have a autopatch command set, make sure the executing command number is at least 2 digits and different than your existing AP command.

Setting Up

rpt.conf

97=autopatchup,context=pass2script,noct=1,farenddisconnect=1,dialtime=90000,quiet=1


So, somewhere in our dialplan, we need to create the context 'pass2script' and this is done in extentions.conf

extentions.conf

[pass2script] ; this context needs to be unique in the system

exten = _X.,1,Wait,1

exten = _X.,n,SayAlpha(/var/lib/asterisk/sounds/activated,${EXTEN}) ; allison says something and then speaks the dtmf string {EXTEN}

exten = _X.,n,Wait,3 ; pause for a chance to cancel by hitting DTMF # (hangup)

exten = _X.,n,System(/source/of/script.sh ${EXTEN}) ; here we pass the dtmf string to shell script.sh

exten = _X.,n,Hangup

Summary

So, *97 12345 in our example here, would pass 12345 to the shell script.sh for *97 is our executing command.

Outside of the 'autopatch' we used to capture and pass the dtmf, this dialplan is pure asterisk and you can use all asterisk dialplan functions for evaluating, reformatting and executing.

You will need your shell script to receive the 'dtmf number string' accordingly and help for that is available on the web as 'passing variables to shell scripts'.

The skinny is that you would use the string inside your shell as "$1" since we have only one 'argument string' to pass for evaluation at a time.

You can evaluate and pass to internal asterisk/app_rpt functions as well, just using the dialplan.

Additionally evaluate that string inside your dialplan and send to different shell scripts.

Search www asterisk help for that. Inside the dialplan, the DTMF string is simply ${EXTEN}


If you like to create your own functionality, you will find this tool/workaround essential for wide flexible control.

It has been well tested method since 2012, so if you are having any issues, check all your syntax.

You could have multiple autopatch dtmf hand-off's as long as you first provide a new unique command number for it and a new unique context for it in your dialplan. i.e.


96=autopatchup,context=sitecontrol,noct=1,farenddisconnect=1,dialtime=90000,quiet=1


97=autopatchup,context=pass2script,noct=1,farenddisconnect=1,dialtime=90000,quiet=1


Practical uses can be site or home control via usb or network relays, radio control/ digital mode control functions, web execution scripts etc, all dependent on your script/dialplan.

So you can see that your imagination is your limit. Go for it.


Example Scripts/DialPlans using this method:

Record system message/ID's - https://wiki.allstarlink.org/wiki/Recording_Audio_Files

DialPlan control for DVSwitch - https://wiki.allstarlink.org/wiki/DialPlan_For_DVSwitch_Tune


More TBA