Yate Community Forum
General Category => Yate users hangout place => Topic started by: jehanzaib_kiani on November 12, 2014, 10:37:25 PM
-
Hi guys,
any one have idea how to catch the hangup event ? so what i am trying to achieve is, i have a route.php script so i want when the call is answered and before hanging up i may catch the hangup event and do my billing stuff for the call.
thanks
-
The message sent when a channel is hungup is chan.hangup.
For billing purposes you may se call.cdr messages.
Check the operation parameter. It will be "finalize" when the channel is hungup.
-
yup, i am looking at it. since i have to do a lot of calculations and the values are coming in different fields. i am really not sure how to acheive this in finalize.
like i run a query and get one values in one variable, then the other value in other variable from a query. can i do something like that? and then insert these values into cdr table?
id = select id from users where username='${external}'
rate = select bill from rates where provider_prefix = substr('".${called}."',1,digit)
-
Hi,
Yes. You can use a stored procedure instead of a single query where you do multiple calculations or you can handle call.cdr with operation=finalize from a script and do the calculations there. Ex: javascript/php script
-
any example will be helpful please. right now i have
cdr_finalize=UPDATE yate_cdr SET billtime = '${billtime}', ringtime = '${ringtime}', `status` = '${status}', reason = '${reason}' WHERE chan = '${chan}' AND billid='${billid}'
so if i call a script how the value will be returned back ?
any example will be helpful.
thanks
-
Hi,
Let's say you use javascript global script,
To start custom script you have to set in javascript.conf in section scripts:
[scripts]
cdrfinalize=cdrfin.js
Then in cdrfin.js (located in share/scripts if you run from sources or /usr/local/share/yate/scripts if you run 'make install').
function onCdrFinalize(msg)
{
if (msg.operation!='finalize')
return false;
// your logic here
}
Message.install(onCdrFinalize, "call.cdr", 50);
This is an example how to run a query in javascript.
http://docs.yate.ro/wiki/How_to_access_a_database_from_Yate%27s_Javascript_module
Also check out the other Javascript documentation:
http://docs.yate.ro/wiki/Javascript
-
great! much appreciated.
do you have any example for php? since all my other scripts are running in scripts. just if you have any or any idea