Author Topic: hangup event?  (Read 12790 times)

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
hangup event?
« 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

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: hangup event?
« Reply #1 on: November 13, 2014, 02:55:18 AM »
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.

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: hangup event?
« Reply #2 on: November 24, 2014, 08:31:15 AM »
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)



Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: hangup event?
« Reply #3 on: November 24, 2014, 10:36:19 AM »
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

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: hangup event?
« Reply #4 on: November 26, 2014, 10:59:43 PM »
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

Monica Tepelus

  • Administrator
  • Full Member
  • *****
  • Posts: 198
    • View Profile
Re: hangup event?
« Reply #5 on: December 02, 2014, 09:55:33 AM »
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

jehanzaib_kiani

  • Newbie
  • *
  • Posts: 45
    • View Profile
Re: hangup event?
« Reply #6 on: December 04, 2014, 01:31:22 AM »
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