Callfile Set: RECORDINGFILE='whatever', failing - asterisk

I am using Asterisk 1.4.44-vici built by abuild # build12 on a i686 running Linux on 2013-05-03 19:48:13 UTC
I have tried several ways to make the following work to no avail:
My callfile successfully calls out and records a message.
I want to send a variable that will be used for the recording file name.
In my callfile I have tried the following methods all failing:
Set: RECORDINGFILE=whatever
SetVar: RECORDINGFILE=whatever
Variable: RECORDINGFILE=whatever
Then in my Extension I have the following, watch for wrapping:
[meetme-outbound]
exten => _9XXXXXXXXXXXXXXXXXXXX1NXXNXXXXXX,1,MixMonitor(/var/spool/asterisk/monitorDONE/MP3/${SIPUSERAGENT}${EXTEN:1}${RECORDINGFILE}${STRFTIME(${EPOCH},$
exten => _9XXXXXXXXXXXXXXXXXXXX1NXXNXXXXXX,n,Dial(SIP/voipessential2/${EXTEN:21},,To)
exten => _9XXXXXXXXXXXXXXXXXXXX1NXXNXXXXXX,n,Hangup
THe above will record the file as if RECORDINGFILE, doesn't exist. Very annoying!
What could I be doing wrong? Is there a configuration setting that I am not aware of?
Any help would be greatly appreciated.
Greg Hill

Variable will be set only on one direction of call
To get variable from other direction use
${SHARED(RECORDINGGILE,${BRIDGEPEER})}
http://www.voip-info.org/wiki/view/Asterisk+Detailed+Variable+List

Related

How do i pass multiple variables to writing ODBC function?

I need to insert some data to SQL ftom Asterisk dialplan. I am using ODBC connection and func_odbc.conf file. There are good way to READ several values from SQl, but apparently, i can't find any working solution for inserting several variables to func_odbc function.
I already tried to use NoOp(ODBC_FunctionName(${ARG1},${ARG2},${ARG3})) and it does not work with 'writesql'. Set(${ODBC_Function()={${ARG1},${ARG2},${ARG3}}) is not working either due to Set limited for one name/value pair.
Here is my func_odbc:
[putClientEvaluation]
;${ARG1} - uniqueid
;${ARG2} - operator
;${ARG3} - client
;${ARG4} - rating
;${ARG5} - queue
dsn=voip
writesql=INSERT INTO cc_service_rating(timestamp,callid,operator,client,rating,queue) values(now(),'${SQL_ESC(${ARG1})}','${SQL_ESC(${ARG2})}','${SQL_ESC(${ARG3})}','${SQL_ESC(${ARG4})}','${SQL_ESC(${ARG5})}')
So i need a working way to pass several arguments at once to odbc writesql function.
UPDATE:
Looks like i just have to use VAL instead of ARG:
writesql=INSERT INTO cc_service_rating(timestamp,callid,operator,client,rating,queue) values(now(),'${SQL_ESC(${VAL1})}','${SQL_ESC(${VAL2})}','${SQL_ESC(${VAL3})}','${SQL_ESC(${VAL4})}','${SQL_ESC(${VAL5})}')
But i still get warning from Set:
WARNING[1227][C-00000020]: pbx_variables.c:1155 pbx_builtin_setvar: Set requires one variable name/value pair.
So, how do i do this without using Set?
UPD:
Did this, no warnings now:
macro extension
exten => s,n,Set(operator=${ARG1})
exten => s,n,Set(quename=${ARG2})
exten => s,n,Set(client=${ARG3})
;timestamp,callid,operator,client,rating,queue
exten => s,n,Set(ODBC_putClientEvaluation()=${UNIQUEID},${operator},${client},${MACRO_EXTEN},${quename})
function
writesql=INSERT INTO cc_service_rating(timestamp,callid,operator,client,rating,queue) values(now(),'${VAL1}','${ARG1}','${ARG3}','${VAL2}','${ARG3}')
Not shure why does this work, obviousely i don't understand how ARG and VAL works here, and why putting args in function brackets does not work at all (even with comma screening).
You are using variables incorrect. Please read book article about variables.
Set(ODBC_Function(${ARG1},${ARG2})=${VAL1},"fixed_param",${VAL3})
I think you should try like this:
Set(ODBC_Function()=${VAR1},"fixed_param",${VAL3});

Updateconfig Asterisk extensions.conf

I am using Asterisk 13. I am trying to modify extensions.conf using AMI.
The line in extensions.conf I'm trying to modify looks like:
Line-000021-000012: exten=_X.,50005,Dial(${dev},20)
I'm trying to change the number of these line 20 by 30.
Using telnet to port 5038 I enter the following:
action:updateconfig
srcfilename:extensions.conf
dstfilename:extensions.conf
Action-000000: update
Cat-000000: stdexten
Var-000000: exten
Value-000000:>_X.,50005,Dial(${dev},30)
This results in:
Response: Success
This action change the Line-000021-000000, but I need to change the Line-000021-000012. How can I do it? Any suggestions?
PD: When I use "Var-000012" instead of "Var-000000" the request is an error.
I have found the solution:
action:updateconfig
srcfilename:extensions.conf
dstfilename:extensions.conf
Action-000000: update
Cat-000000: stdexten
Var-000000: exten
Match-000000: _X.,50005,Dial(${dev},20)
Value-000000:>_X.,50005,Dial(${dev},30)

Asterisk Functions in PHPAGI

I wanted to use an Asterisk Function "IFTIME" in PHPAGI. The following syntax runs correctly in Dialplan but I have been trying to make it work in PHPAGI.
exten => 1234,1,Set(foo=${IFTIME(16:00-21:00,*,*,*?true:false)})
exten => 1234,2,NoOp(${foo})
So far in PHPAGI this is what I have done
** I am using AGISPEEDY framework, it uses PHPAGI
$agi->agi_exec('Set','fo o=${IFTIME(*,*,*,*?true:false)}');
$result = $agi->get_variable('foo');
$agi->verbose($result);
------result-------
Array(
[code] => 200
[result] => 1
[data] => ${IFTIME(*,*,*,*?true:false)}
)
The above command set the function as a string. I tried changing
this: $agi->agi_exec('Set','foo=${IFTIME(*,*,*,*?true:false)}');
to: $agi->set_variable('foo','${IFTIME(*,*,*,*?true:false)}');
but result is same, it saves ${IFTIME(*,*,*,*?true:false)} as a string.
Any help on how to run an Asterisk Function like IFTIME from PHPAGI would be highly appreciated.
You have use get_full_variable if you use functions.
You are trying to fly to the moon by landing a rocket ship on Mars, what you are doing is pointless.
You are already inside a PHP script, just emulate the same check of IFTIME inside PHP. So, in your case, I will replace the agi_exec command with something like:
$current_timestamp = time();
$current_time = (int)date("Hi", $current_timestamp);
if (($current_time > 1600) && ($current_time < 2100)) {
.. Do some cool PHP here ..
}
This segment wasn't debugged, so it may not work as you think, but you get the idea.
PHPAGI and AGI in general are wonderful tools - when used the right way. You are trying to leverage a Dialplan function/application in order to do something that you would normally do in PHP.

MixMonitor - How to use lame to convert and then remove the source file?

How can I remove the source wav file after the call is finished? If I have to use AGI can I have an example script?
This is how I'm using MixMonitor
exten => s,n,MixMonitor(${source_file}.wav,W(1),lame -V3 ${source_file}.wav ${mp3_from_source}.mp3)
Fails because it is deleted before the conversion.
exten => h,n,System(rm ${source_file}.wav)
How about:
exten => s,n,MixMonitor(${source_file}.wav,W(1),lame -V3 ${source_file}.wav ${mp3_from_source}.mp3 && rm ${source_file}.wav)
and skip the call in h?
Honestly, you need to stop being creative. Just exec the system level calls as separate dial plan lines. One line for mixmonitor, one line for lame, verify the return value of lame, then delete. This is what I do in my applications, and it works perfect. You don't need to combine every step of the conversion process into a single dialplan line.
I use this command line:
/usr/local/bin/lame -b16 --noshort "/var/spool/asterisk/monitor/$1.wav" "/var/www/html/asterisk/calls/$1.mp3"

Function that returns a value in extensions.conf - asterisk

I want to do the following in my extensions.conf in asterisk:
Read in a number entered by a user. - easy
Feed that number into a script which returns a wav file.
This wav file is then played.
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.
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})
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.

Resources