if you set the channel variable 'session_in_hangup_hook=true' early in the call, the session will be present in your script.<br><br><br><br><div class="gmail_quote">2009/3/31 Keith Laaks <span dir="ltr"><<a href="mailto:keithl@voxtelecom.co.za">keithl@voxtelecom.co.za</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">Hi,</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">Here is what I am trying to accomplish:</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">//--- completecall.js trigged via api_hangup_hook ----</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">use("CURL");</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">const loglevel='notice';</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">var uuid =
request.getHeader("Core-UUID"); </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">var billmsec = request.getHeader("billmsec");</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">var urlrequest = "UUID=" + uuid + "&billmsec="
+ billmsec;</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">function reply_callback(string, arg) {</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> string =
string.substring(string.search("API")+3);</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> string =
string.substring(0,string.search("<"));</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> var splits = string.split("~");</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> var i = 0;</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> var length = splits.length;</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> for (i=0; i < length; i++) {</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> var fv=splits[i].split("=");</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> console_log(loglevel, "setting: " +
fv[0] + " = " + fv[1] + "\n");</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> //session.setVariable(fv[0],fv[1]); // Cant
use set here as the session is dead by now - the call has been terminated</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> }</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> return true;</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">}</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">var curl = new CURL();</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">console_log(loglevel,"-- completecall.js ->" + url
+ "?" + urlrequest + "\n");</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">var env = request.dumpENV("text"); // debug</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">console_log("ENV:\n", env + "\n"); // debug</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">curl.run("POST",
"<a href="http://127.0.0.1:10502/rate" target="_blank">http://127.0.0.1:10502/rate</a>", urlrequest, reply_callback,
"CBrate\n");</span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">//returns string like
<sometag>APIcharge=10.20</sometag></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);">exit();</span></p>
<div style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1pt; padding: 0cm 0cm 1pt;">
<p style="border: medium none ; padding: 0cm;"><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
</div>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">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).
</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">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.</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">Note that in the above, the external system will return ‘charge=value’.
</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">I need to set the variable ‘charge’ to the value in ‘value’.</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">Then using the config below, ‘charge’ can be written
out as one of the cdr fields.</span></p>
<div style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1pt; padding: 0cm 0cm 1pt;">
<p style="border: medium none ; padding: 0cm;"><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
</div>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"><configuration name="cdr_csv.conf" description="CDR
CSV Format"></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <settings></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <!-- 'cdr-csv' will always be appended to
log-base --></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <!--<param name="log-base"
value="/var/log"/>--></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <param name="default-template"
value="def"/></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <!-- This is like the info app but after
the call is hung up --></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <param name="debug"
value="true"/></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <param name="rotate-on-hup"
value="true"/></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <!-- may be a b or ab --></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <param name="legs"
value="a"/></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </settings></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <templates></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> <template name="def">"${accountcode}","${billsec}","${charge}","${sip_req_user}","${hangup_cause}","${uuid}","${bleg_uuid}"</template></span></p>
<p><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"> </templates></span></p>
<div style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1pt; padding: 0cm 0cm 1pt;">
<p style="border: medium none ; padding: 0cm;"><span style="font-size: 11pt; font-family: "Courier New"; color: rgb(31, 73, 125);"></configuration></span></p>
</div>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">Best Regards</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">Keith</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0cm 0cm;">
<p><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> Anthony Minessale
[mailto:<a href="mailto:anthony.minessale@gmail.com" target="_blank">anthony.minessale@gmail.com</a>] <br>
<b>Sent:</b> 31 March 2009 00:13<br>
<b>To:</b> <a href="mailto:freeswitch-users@lists.freeswitch.org" target="_blank">freeswitch-users@lists.freeswitch.org</a><br>
<b>Subject:</b> Re: [Freeswitch-users] Javascript, Hanguphooks,CDRs and User
Variables.</span></p>
</div><div><div></div><div class="h5">
<p> </p>
<p style="margin-bottom: 12pt;">in your script called via
api_hangup_hook:<br>
<br>
var env = request.dumpENV("text");<br>
<br>
consoleLog("info", env);<br>
<br>
all those vars are there for you, you can get the individually with <br>
var hval = request.getHeader("some_header");<br>
<br>
</p>
<div>
<p>2009/3/30 Keith Laaks <<a href="mailto:keithl@voxtelecom.co.za" target="_blank">keithl@voxtelecom.co.za</a>></p>
<div>
<div>
<p>Hi,</p>
<p> </p>
<p>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.</p>
<p> </p>
<p>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.</p>
<p> </p>
<p>Any advice / suggestions would be appreciated.</p>
<p> </p>
<p>Best Regards</p>
<p> </p>
<p><span style="font-size: 10pt; color: black;">Keith</span></p>
<p><span style="font-size: 10pt; color: black;"> </span></p>
</div>
</div>
<p style="margin-bottom: 12pt;"><br>
_______________________________________________<br>
Freeswitch-users mailing list<br>
<a href="mailto:Freeswitch-users@lists.freeswitch.org" target="_blank">Freeswitch-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a></p>
</div>
<p><br>
<br clear="all">
<br>
-- <br>
Anthony Minessale II<br>
<br>
FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>
ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
<br>
AIM: anthm<br>
<a href="mailto:MSN%3Aanthony_minessale@hotmail.com" target="_blank">MSN:anthony_minessale@hotmail.com</a><br>
GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com" target="_blank">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br>
<br>
FreeSWITCH Developer Conference<br>
<a href="mailto:sip%3A888@conference.freeswitch.org" target="_blank">sip:888@conference.freeswitch.org</a><br>
<a href="http://iax:guest@conference.freeswitch.org/888" target="_blank">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org" target="_blank">googletalk:conf+888@conference.freeswitch.org</a><br>
pstn:213-799-1400</p>
</div></div></div>
</div>
<br>_______________________________________________<br>
Freeswitch-users mailing list<br>
<a href="mailto:Freeswitch-users@lists.freeswitch.org">Freeswitch-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/">http://www.cluecon.com/</a><br>
<br>AIM: anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net">irc.freenode.net</a> #freeswitch<br><br>FreeSWITCH Developer Conference<br><a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br><a href="http://iax:guest@conference.freeswitch.org/888">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:213-799-1400<br>