Reputation: 10578
I want to do the following in my extensions.conf in asterisk:
I know the system
command, but have not been able to figure out a way for it to return a value.
Any help is most welcome,
Thanks,
Sriram.
Upvotes: 0
Views: 2243
Reputation: 10578
One can have the program/script write the value to a file and then use the functions within asterisk such as ReadFile
to get the value. This can be done like so:
Within the script:
echo -n ${value} > ${fileName}
From within asterisk:
exten => 0,n,ReadFile(ValueReadFromFile=${fileName},${MAX_FILE_CHAR})
where: ${MAX_FILE_CHAR}
is the max. characters that need to be read from the file ${fileName}
. The value you want read will be stored in ValueReadFromFile
.
Upvotes: 0
Reputation: 54342
For such things I use Asterisk AGI. Idea is similar to CGI scripts for Web servers. You can use various languages, but I use Python with pyst: Python for Asterisk library. Such AGI script/program can read or set channel variable and this way communicate with Asterisk dialplan.
Example of such code with pyst agilib
:
wav_to_play = 'other.wav'
user_nr = agilib.get_variable('user_entered_number')
if not user_nr:
wav_to_play = 'nothing.wav'
elif user_nr.endswith('0'):
wav_to_play = 'zero.wav'
# ...
agilib.set_variable('wav_selected', wav_to_play)
After saving such code in wav_selector.agi
(you must add normal Python header, libs etc) you can use it in dialplan like:
exten => s,n,Set(user_entered_number=5)
exten => s,n,AGI(wav_selector.agi)
exten => s,n,Background((${wav_selected})
Upvotes: 1