<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<div><br>
<div class="acompli_signature">Anthony,</div>
<div class="acompli_signature"><br>
</div>
<div class="acompli_signature">Many thanks for your detailed response. It now makes sense to me and I will adjust my code appropriately. </div>
<div class="acompli_signature"><br>
</div>
<div class="acompli_signature">Andrew</div>
<br>
</div>
<div class="gmail_quote">_____________________________<br>
From: Anthony Minessale <<a href="mailto:anthony.minessale@gmail.com" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="1">anthony.minessale@gmail.com</a>><br>
Sent: Friday, February 27, 2015 5:08 pm<br>
Subject: Re: [Freeswitch-users] Re- FreeSWITCH CDRs ${billsec} not correct when using Lua scripts and running a hangup handler with any delays inside it<br>
To: FreeSWITCH Users Help <<a href="mailto:freeswitch-users@lists.freeswitch.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="3">freeswitch-users@lists.freeswitch.org</a>><br>
<br>
<br>
<meta content="text/html; charset=utf-8">
<div dir="ltr">I would say you did not actually understand what he was saying based on your response.
<div><br>
</div>
<div>I can try to explain: </div>
<div><br>
</div>
<div>The channel is busy executing your script. All scripts must exit immediately when the channel is transferred or hungup. That's why you must always wrap things in session:ready()
</div>
<div>If you hangup the call from your script the next thing you MUST do is exit from the script so the session can transition to the hangup state. Until then it will never be able to complete the EXECUTE state.
</div>
<div>What you can do is set the api_hangup_hook to another lua script that can run once the call is hungup or use CDRS to process billing data from another system designated for billing.
</div>
<div><br>
</div>
<div>You may not like the idea now but one day you will come to understand that doing call logic and billing all in the same script in the foreground of the call is not a good way to do things.
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Feb 26, 2015 at 8:27 PM, Andrew Keil <span dir="ltr">
<<a href="mailto:andrew.keil@visytel.com">andrew.keil@visytel.com</a>></span> wrote:
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-AU">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Steven,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Many thanks for your fast response. I understand what you are saying, however even when I add “session:hangup()” as the first line inside my hangup handler (function
myHangupHook(s, status, arg)), that is prior to the pause of 5 seconds waiting for an event that never comes (at the moment) the resulting CDRs are based on when the Lua script completes (it seems) and not when the call disconnects. I fully understand that
this is a two way conversation (ie. Remote Disconnect received then Release sent and Release Complete received).
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Does this mean there is no way (within Lua under FreeSWITCH) to clear up a call correctly, then complete some extra code within the Lua script, then end the Lua
script and generate correct CDRs from within FreeSWITCH?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Regarding subscribing to the HANGUP event or using the Lua script to fire events to a third party application I will be looking into this, however I thought I
would first ask if I was missing something within FreeSWITCH.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">One more question is there a FreeSWITCH action to correctly release the call apart from session:hangup() {which obviously does not work when the remote end disconnects
first}?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I am more than happy to experiment with any ideas.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Andrew<u></u><u></u></span></p>
<p class="MsoNormal"><a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></a></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">
<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org">freeswitch-users-bounces@lists.freeswitch.org</a>]
<b>On Behalf Of </b>Steven Ayre<br>
<b>Sent:</b> Friday, 27 February 2015 10:47 AM<br>
<b>To:</b> FreeSWITCH Users Help<br>
<b>Subject:</b> Re: [Freeswitch-users] Re- FreeSWITCH CDRs ${billsec} not correct when using Lua scripts and running a hangup handler with any delays inside it<u></u><u></u></span></p>
<div>
<div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Sorry, jumped the gun a little based on the subject.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">A more relevant answer is that during the hangup state the call is still in the process of hanging up, it isn't hung up and ended until the hangup_complete event. So your 5s sleep is extending the life of the call.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Is it perhaps possible to subscribe to the hangup event and process it asyncronously?<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On 26 February 2015 at 23:32, Steven Ayre <<a href="mailto:steveayre@gmail.com">steveayre@gmail.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<p class="MsoNormal">CDR processing should be done in the reporting not hangup state.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<p class="MsoNormal">On 26 February 2015 at 22:50, Andrew Keil <<a href="mailto:andrew.keil@visytel.com">andrew.keil@visytel.com</a>> wrote:<u></u><u></u></p>
</div>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<div>
<div>
<p class="MsoNormal">To FreeSWITCH users,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I am currently experimenting with Lua scripts on FreeSWITCH (latest build) and found an interesting issue with FreeSWITCH default CDRs (inside log/cdr-csv/1000.csv).<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">See below for my simple Lua script called from a diaplan as follows:<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><include><u></u><u></u></p>
<p class="MsoNormal"> <!-- To test Lua script --><u></u><u></u></p>
<p class="MsoNormal"> <extension name="ivr_demo"><u></u><u></u></p>
<p class="MsoNormal"> <condition field="destination_number" expression="^(9101)$"><u></u><u></u></p>
<p class="MsoNormal"> <action application="lua" data="myservice.lua"/>
<u></u><u></u></p>
<p class="MsoNormal"> </condition><u></u><u></u></p>
<p class="MsoNormal"> </extension><u></u><u></u></p>
<p class="MsoNormal"></include><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">What I noticed is that placing a call into FreeSWITCH via a SIP phone (calling 9101) and landing on myservice.lua everything processes as expected. If I hangup after 3 seconds then I should expect the CDR to show ${billsec} = 3. However
this is not the case since both ${duration} and ${billsec} are actually set once the Lua script completes (not based on HANGUP). So inside 1000.csv I see duration and billsec both having 8 seconds.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">You will see below that inside my hangup handler (function myHangupHook(s, status, arg)) I fire an event and wait up to 5000ms for an event to be returned (currently I am not returning an event so the 5000ms will take place). This explains
the extra 5 seconds after the 3 seconds of the call.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">My question is since FreeSWITCH knows that the HANGUP has taken place why is the ${billsec} not correct (ie. should be 3 seconds)?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I tried adding “session:hangup()” as the first line inside my hangup handler (function myHangupHook(s, status, arg)) and this made no difference.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Is there a solution to this issue? Perhaps there is a different CDR variable that will contain the correct duration based on when HANGUP was actually received.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thanks in advance for any assistance with this.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Regards,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Andrew Keil<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Simple Lua Script:<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">-- myservice.lua<u></u><u></u></p>
<p class="MsoNormal">-- To test a simple service<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">function MainService()<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION ")<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> -- answer the call<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "ANSWER CALLER ")<u></u><u></u></p>
<p class="MsoNormal"> session:answer();<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> -- sleep a second<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Sleep for 1000ms ")<u></u><u></u></p>
<p class="MsoNormal"> session:sleep(1000);<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Playing 12345 ")<u></u><u></u></p>
<p class="MsoNormal"> session:say("12345", "en", "number", "pronounced");<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Finished playing 12345 ")<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> if (session:ready()) then<u></u><u></u></p>
<p class="MsoNormal"> -- hangup<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "HANGUP ")<u></u><u></u></p>
<p class="MsoNormal"> session:hangup() <u></u><u></u></p>
<p class="MsoNormal"> end<u></u><u></u></p>
<p class="MsoNormal">end<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">--------------------------------------------------------------------------------------------<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">-- Functions section …<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">function myHangupHook(s, status, arg)<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "myHangupHook: " .. status .. " ")<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> -- send hangup event test (after caller hangs up)<u></u><u></u></p>
<p class="MsoNormal"> local event = freeswitch.Event("CUSTOM", "visytel::HANGUP?")<u></u><u></u></p>
<p class="MsoNormal"> event:addHeader("hi", "there")<u></u><u></u></p>
<p class="MsoNormal"> event:addHeader("channel-uuid", channeluuid)<u></u><u></u></p>
<p class="MsoNormal"> -- Add Event consumer if a response is required!<u></u><u></u></p>
<p class="MsoNormal"> local con = freeswitch.EventConsumer("CUSTOM", "visytel::HANGUP!")<u></u><u></u></p>
<p class="MsoNormal"> -- fire event<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Fire HANGUP event ")
<u></u><u></u></p>
<p class="MsoNormal"> event:fire() <u></u><u></u></p>
<p class="MsoNormal"> -- Wait for 5000ms to test response<u></u><u></u></p>
<p class="MsoNormal"> local retevent = con:pop(1, 5000)<u></u><u></u></p>
<p class="MsoNormal"> if retevent then<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", "Reply received! ")<u></u><u></u></p>
<p class="MsoNormal"> freeswitch.consoleLog("INFO", string.format("Reply received: %s ",retevent:getHeader("Result")))<u></u><u></u></p>
<p class="MsoNormal"> end<u></u><u></u></p>
<p class="MsoNormal">end<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">-- Setup handlers here<u></u><u></u></p>
<p class="MsoNormal">myparam="empty";<u></u><u></u></p>
<p class="MsoNormal">session:setHangupHook("myHangupHook", "myparam")<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">-- Source channel-uuid here {used inside myHangupHook handler and for all fired events inside the header<u></u><u></u></p>
<p class="MsoNormal">channeluuid = session:getVariable("uuid");<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">MainService()<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">-- End of lua script<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal">_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com">http://www.cluecon.com</a><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">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org">http://www.freeswitch.org</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</div>
</div>
<br>
_________________________________________________________________________ <br>
Professional FreeSWITCH Consulting Services: <br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a> <br>
<a href="http://www.freeswitchsolutions.com">http://www.freeswitchsolutions.com</a>
<br>
<br>
Official FreeSWITCH Sites <br>
<a href="http://www.freeswitch.org">http://www.freeswitch.org</a> <br>
<a href="http://confluence.freeswitch.org">http://confluence.freeswitch.org</a> <br>
<a href="http://www.cluecon.com">http://www.cluecon.com</a> <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">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a>
<br>
UNSUBSCRIBE: <a href="http://lists.freeswitch.org/mailman/options/freeswitch-users">
http://lists.freeswitch.org/mailman/options/freeswitch-users</a> <br>
<a href="http://www.freeswitch.org">http://www.freeswitch.org</a> <br>
</blockquote>
</div>
<br>
<br>
<div><br>
</div>
-- <br>
<div class="gmail_signature">
<div dir="ltr">Anthony Minessale II ♬ @anthmfs ♬ @FreeSWITCH ♬
<div><br>
<div>☞ <a href="http://freeswitch.org/">http://freeswitch.org/</a> ☞ <a href="http://cluecon.com/">
http://cluecon.com/</a> ☞ <a href="http://twitter.com/FreeSWITCH">http://twitter.com/FreeSWITCH</a>
</div>
<div>
<div>☞ <a href="http://irc.freenode.net">irc.freenode.net</a> #freeswitch ☞ <u><a href="http://freeswitch.org/g+">http://freeswitch.org/g+</a></u>
<br>
<br>
</div>
<div>ClueCon Weekly Development Call <br>
</div>
<div>☎ <a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a> ☎
<a href="tel:+19193869900" x-apple-data-detectors="true" x-apple-data-detectors-type="telephone" x-apple-data-detectors-result="38">
+19193869900</a> </div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<br>
</div>
</body>
</html>