Passing DTMF to shell scripts: Difference between revisions

From AllStarLink Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
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.
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.
So if you have a phonepatch command set, make sure the executing command number is at least 2 digits and different than your existing AP command.
 
It is now suggested here that you use prefix starting with 6x and keep your commands listed together with the AP command in numerical order for better understanding.
For what you are actually doing is dialing by 'CONTEXT' and quietly.
It is also suggested here as you will eventually build many of these commands, that you change your existing from the current standard.
Like *60 for patch hangup or even *0
And *61 for your normal phone patch.
Other similar commands can go from there *62 *63 etc. It's unlikely you will build more than 9, but it could be. So just extend them by adding a digit to 'ALL' of them. 6xx.
If you do not extend the digit to them all starting with 6, you may find some of them will not execute at all. EX: *62 & *621. *621 will never execute. Asterisk first match wins.


==Setting Up==
==Setting Up==
===rpt.conf===
===rpt.conf===


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




Line 29: Line 37:


==Summary==
==Summary==
So, *97 12345  in our example here, would pass 12345 to the shell script.sh for *97 is our executing command.
So, *64 12345  in our example here, would pass 12345 to the shell script.sh for *64 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.
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.
Line 52: Line 60:




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




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




Line 64: Line 72:




==Useful Example Scripts:==
==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
 


TBC
More TBA

Latest revision as of 22:03, 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 phonepatch command set, make sure the executing command number is at least 2 digits and different than your existing AP command.

It is now suggested here that you use prefix starting with 6x and keep your commands listed together with the AP command in numerical order for better understanding. For what you are actually doing is dialing by 'CONTEXT' and quietly. It is also suggested here as you will eventually build many of these commands, that you change your existing from the current standard. Like *60 for patch hangup or even *0 And *61 for your normal phone patch. Other similar commands can go from there *62 *63 etc. It's unlikely you will build more than 9, but it could be. So just extend them by adding a digit to 'ALL' of them. 6xx. If you do not extend the digit to them all starting with 6, you may find some of them will not execute at all. EX: *62 & *621. *621 will never execute. Asterisk first match wins.

Setting Up

rpt.conf

64=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, *64 12345 in our example here, would pass 12345 to the shell script.sh for *64 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.


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


66=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