Javascript, Hanguphooks, CDRs and User Variables.
Hi, I have an application where my Javascript hanguphook code calculates a value (e.g. the cost of the call which can only be calculated post hangup) and I need to have that value appear as a field in the cdrs. As the 'session' object is no longer available for javascript logic post hangup, I can't figure out how to 'set' a user variable post hangup, such that it can be written to the cdr when the state changes from CS_HANGUP -> CS_REPORTING. Maybe it's just not possible......? It would be a pity to have to resort to writing out cdrs from the javascript itself and duplicating what fs does so well already. Any advice / suggestions would be appreciated. Best Regards Keith
Are logging both a- and b-legs? Just curious what your setup is. -MC 2009/3/30 Keith Laaks <keithl@voxtelecom.co.za>
Hi,
I have an application where my Javascript hanguphook code calculates a value (e.g. the cost of the call which can only be calculated post hangup) and I need to have that value appear as a field in the cdrs.
As the ‘session’ object is no longer available for javascript logic post hangup, I can’t figure out how to ‘set’ a user variable post hangup, such that it can be written to the cdr when the state changes from CS_HANGUP -> CS_REPORTING. Maybe it’s just not possible……? It would be a pity to have to resort to writing out cdrs from the javascript itself and duplicating what fs does so well already.
Any advice / suggestions would be appreciated.
Best Regards
Keith
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
in your script called via api_hangup_hook: var env = request.dumpENV("text"); consoleLog("info", env); all those vars are there for you, you can get the individually with var hval = request.getHeader("some_header"); 2009/3/30 Keith Laaks <keithl@voxtelecom.co.za>
Hi,
I have an application where my Javascript hanguphook code calculates a value (e.g. the cost of the call which can only be calculated post hangup) and I need to have that value appear as a field in the cdrs.
As the ‘session’ object is no longer available for javascript logic post hangup, I can’t figure out how to ‘set’ a user variable post hangup, such that it can be written to the cdr when the state changes from CS_HANGUP -> CS_REPORTING. Maybe it’s just not possible……? It would be a pity to have to resort to writing out cdrs from the javascript itself and duplicating what fs does so well already.
Any advice / suggestions would be appreciated.
Best Regards
Keith
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
Hi, Here is what I am trying to accomplish: //--- completecall.js trigged via api_hangup_hook ---- use("CURL"); const loglevel='notice'; var uuid = request.getHeader("Core-UUID"); var billmsec = request.getHeader("billmsec"); var urlrequest = "UUID=" + uuid + "&billmsec=" + billmsec; function reply_callback(string, arg) { string = string.substring(string.search("API")+3); string = string.substring(0,string.search("<")); var splits = string.split("~"); var i = 0; var length = splits.length; for (i=0; i < length; i++) { var fv=splits[i].split("="); console_log(loglevel, "setting: " + fv[0] + " = " + fv[1] + "\n"); //session.setVariable(fv[0],fv[1]); // Cant use set here as the session is dead by now - the call has been terminated } return true; } var curl = new CURL(); console_log(loglevel,"-- completecall.js ->" + url + "?" + urlrequest + "\n"); var env = request.dumpENV("text"); // debug console_log("ENV:\n", env + "\n"); // debug curl.run("POST", "http://127.0.0.1:10502/rate", urlrequest, reply_callback, "CBrate\n"); //returns string like <sometag>APIcharge=10.20</sometag> exit(); So the trick is that I am accessing an external system via CURL where the call rate is calculated and returned (based on the call duration and uuid). Now I need to use a 'setVariable' to get it back as one of the parameters that the cdr module can write out for me. Note that in the above, the external system will return 'charge=value'. I need to set the variable 'charge' to the value in 'value'. Then using the config below, 'charge' can be written out as one of the cdr fields. <configuration name="cdr_csv.conf" description="CDR CSV Format"> <settings> <!-- 'cdr-csv' will always be appended to log-base --> <!--<param name="log-base" value="/var/log"/>--> <param name="default-template" value="def"/> <!-- This is like the info app but after the call is hung up --> <param name="debug" value="true"/> <param name="rotate-on-hup" value="true"/> <!-- may be a b or ab --> <param name="legs" value="a"/> </settings> <templates> <template name="def">"${accountcode}","${billsec}","${charge}","${sip_req_user}"," ${hangup_cause}","${uuid}","${bleg_uuid}"</template> </templates> </configuration> Best Regards Keith From: Anthony Minessale [mailto:anthony.minessale@gmail.com] Sent: 31 March 2009 00:13 To: freeswitch-users@lists.freeswitch.org Subject: Re: [Freeswitch-users] Javascript, Hanguphooks,CDRs and User Variables. in your script called via api_hangup_hook: var env = request.dumpENV("text"); consoleLog("info", env); all those vars are there for you, you can get the individually with var hval = request.getHeader("some_header"); 2009/3/30 Keith Laaks <keithl@voxtelecom.co.za> Hi, I have an application where my Javascript hanguphook code calculates a value (e.g. the cost of the call which can only be calculated post hangup) and I need to have that value appear as a field in the cdrs. As the 'session' object is no longer available for javascript logic post hangup, I can't figure out how to 'set' a user variable post hangup, such that it can be written to the cdr when the state changes from CS_HANGUP -> CS_REPORTING. Maybe it's just not possible......? It would be a pity to have to resort to writing out cdrs from the javascript itself and duplicating what fs does so well already. Any advice / suggestions would be appreciated. Best Regards Keith _______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org -- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <mailto:MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com <mailto:PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <mailto:sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org <mailto:googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
if you set the channel variable 'session_in_hangup_hook=true' early in the call, the session will be present in your script. 2009/3/31 Keith Laaks <keithl@voxtelecom.co.za>
Hi,
Here is what I am trying to accomplish:
//--- completecall.js trigged via api_hangup_hook ----
use("CURL");
const loglevel='notice';
var uuid = request.getHeader("Core-UUID");
var billmsec = request.getHeader("billmsec");
var urlrequest = "UUID=" + uuid + "&billmsec=" + billmsec;
function reply_callback(string, arg) {
string = string.substring(string.search("API")+3);
string = string.substring(0,string.search("<"));
var splits = string.split("~");
var i = 0;
var length = splits.length;
for (i=0; i < length; i++) {
var fv=splits[i].split("=");
console_log(loglevel, "setting: " + fv[0] + " = " + fv[1] + "\n");
//session.setVariable(fv[0],fv[1]); // Cant use set here as the session is dead by now - the call has been terminated
}
return true;
}
var curl = new CURL();
console_log(loglevel,"-- completecall.js ->" + url + "?" + urlrequest + "\n");
var env = request.dumpENV("text"); // debug
console_log("ENV:\n", env + "\n"); // debug
curl.run("POST", "http://127.0.0.1:10502/rate", urlrequest, reply_callback, "CBrate\n");
//returns string like <sometag>APIcharge=10.20</sometag>
exit();
So the trick is that I am accessing an external system via CURL where the call rate is calculated and returned (based on the call duration and uuid).
Now I need to use a ‘setVariable’ to get it back as one of the parameters that the cdr module can write out for me.
Note that in the above, the external system will return ‘charge=value’.
I need to set the variable ‘charge’ to the value in ‘value’.
Then using the config below, ‘charge’ can be written out as one of the cdr fields.
<configuration name="cdr_csv.conf" description="CDR CSV Format">
<settings>
<!-- 'cdr-csv' will always be appended to log-base -->
<!--<param name="log-base" value="/var/log"/>-->
<param name="default-template" value="def"/>
<!-- This is like the info app but after the call is hung up -->
<param name="debug" value="true"/>
<param name="rotate-on-hup" value="true"/>
<!-- may be a b or ab -->
<param name="legs" value="a"/>
</settings>
<templates>
<template name="def">"${accountcode}","${billsec}","${charge}","${sip_req_user}","${hangup_cause}","${uuid}","${bleg_uuid}"</template>
</templates>
</configuration>
Best Regards
Keith
*From:* Anthony Minessale [mailto:anthony.minessale@gmail.com] *Sent:* 31 March 2009 00:13 *To:* freeswitch-users@lists.freeswitch.org *Subject:* Re: [Freeswitch-users] Javascript, Hanguphooks,CDRs and User Variables.
in your script called via api_hangup_hook:
var env = request.dumpENV("text");
consoleLog("info", env);
all those vars are there for you, you can get the individually with var hval = request.getHeader("some_header");
2009/3/30 Keith Laaks <keithl@voxtelecom.co.za>
Hi,
I have an application where my Javascript hanguphook code calculates a value (e.g. the cost of the call which can only be calculated post hangup) and I need to have that value appear as a field in the cdrs.
As the ‘session’ object is no longer available for javascript logic post hangup, I can’t figure out how to ‘set’ a user variable post hangup, such that it can be written to the cdr when the state changes from CS_HANGUP -> CS_REPORTING. Maybe it’s just not possible……? It would be a pity to have to resort to writing out cdrs from the javascript itself and duplicating what fs does so well already.
Any advice / suggestions would be appreciated.
Best Regards
Keith
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II
FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/
AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch
FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
On Mar 31, 2009, at 5:59 AM, Anthony Minessale <anthony.minessale@gmail.com
wrote:
if you set the channel variable 'session_in_hangup_hook=true' early in the call, the session will be present in your script.
Very cool. I will get this chan var documented on the wiki right away. -MC
participants (4)
-
Anthony Minessale
-
Keith Laaks
-
Michael Collins
-
Michael S Collins