<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I have to double check, but this may leak memory...&nbsp;<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 4, 2016, at 11:56 AM, Chad Phillips &lt;<a href="mailto:chad@apartmentlines.com" class="">chad@apartmentlines.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">In cases where I've run Lua scripts on startup, I'll use a global variable, and periodically check it like so:<div class=""><br class=""></div><div class="">&nbsp; kill_script = api:executeString("global_getvar custom_lua_kill_script")<br class=""></div><div class=""><br class=""></div><div class="">If the variable is set to a specified value, then I take steps to end the script, which usually just means breaking out of an infinite loop.</div><div class=""><br class=""></div><div class="">This variable can be adjusted in a number of ways, including another Lua script, directly from CLI, or even by setting a timer using the schedule API in the same script:</div><div class=""><br class=""></div><div class=""><div class="">&nbsp; command = string.format([[sched_api %d none global_setvar&nbsp;custom_lua_kill_script=true]], shutdown_stamp)</div><div class="">&nbsp; api:executeString(command)</div></div><div class=""><br class=""></div><div class="">Not the most elegant solution, but it works.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Mar 4, 2016 at 5:55 AM, Abaci B <span dir="ltr" class="">&lt;<a href="mailto:abaci64@gmail.com" target="_blank" class="">abaci64@gmail.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="">I still think there should be a way to exit a lua script without calling a hangup hook, this is needed for lua scripts with no session and even in some scenarios where there is a session.</div><div class="">I think I'll open a feature request on Jira for that, unless someone knows a way to do this?</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Feb 29, 2016 at 5:09 PM, Andrew Keil <span dir="ltr" class="">&lt;<a href="mailto:andrew.keil@visytel.com" target="_blank" class="">andrew.keil@visytel.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-AU" vlink="purple" link="blue" class="">
<div class=""><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">Abaci B,<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""><u class=""></u>&nbsp;<u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">Thanks so much for sourcing the JIRA topic!<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""><u class=""></u>&nbsp;<u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">You were right, by placing the return “exit” inside the hanguphook handler then the sript does stop and abort with an error.&nbsp; I have made this cleaner
 by adding debug.traceback=nil just prior.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""><u class=""></u>&nbsp;<u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">So now my hangup hook handler looks like this:<u class=""></u><u class=""></u></span></p><span class=""><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""><u class=""></u>&nbsp;<u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">function myHangupHook(s, status, arg)<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">&nbsp;&nbsp;&nbsp; session:hangup()<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">&nbsp;&nbsp;&nbsp; CleanUp() -- Run CleanUp function now since the caller has disconnected<u class=""></u><u class=""></u></span></p>
</span><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">&nbsp;&nbsp;&nbsp; debug.traceback=nil<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">&nbsp;&nbsp;&nbsp; return "exit"&nbsp;
<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">end<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""><u class=""></u>&nbsp;<u class=""></u></span></p><p class="MsoNormal"><a name="1430673312_183271413__MailEndCompose" class=""><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">Obviously this generates the message: “2016-03-01 09:01:18.625809 [ERR] mod_lua.cpp:203 exit”<u class=""></u><u class=""></u></span></a></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">in the console, but this I can live with especially to avoid the goto statements throughout the code after every audio related function.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""><u class=""></u>&nbsp;<u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">Thanks again.<u class=""></u><u class=""></u></span></p><span class=""><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""><u class=""></u>&nbsp;<u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">Andrew Keil<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><b class=""><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">Visytel Pty Ltd<u class=""></u><u class=""></u></span></b></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""><u class=""></u>&nbsp;<u class=""></u></span></p>
</span><p class="MsoNormal"><b class=""><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class=""> <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank" class="">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank" class="">freeswitch-users-bounces@lists.freeswitch.org</a>]
<b class="">On Behalf Of </b>Abaci B<br class="">
<b class="">Sent:</b> Tuesday, 1 March 2016 3:16 AM</span></p><div class=""><div class=""><br class="">
<b class="">To:</b> FreeSWITCH Users Help &lt;<a href="mailto:freeswitch-users@lists.freeswitch.org" target="_blank" class="">freeswitch-users@lists.freeswitch.org</a>&gt;<br class="">
<b class="">Subject:</b> Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function<u class=""></u><u class=""></u></div></div><div class=""><br class="webkit-block-placeholder"></div><div class=""><div class=""><p class="MsoNormal"><u class=""></u>&nbsp;<u class=""></u></p>
<div class="">
<div class=""><p class="MsoNormal">I don't see in your example above where you have a return "exit" in your hangup hook function<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">see <a href="https://freeswitch.org/jira/browse/FS-3841" target="_blank" class="">https://freeswitch.org/jira/browse/FS-3841</a><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">seems like the "exit" or "die" needs to be returned directly from the hanguphook function so try from that function (not cleanup function) to return "exit" or "dye", also it seems
<u class=""></u><u class=""></u></p>
</div>
</div>
<div class=""><p class="MsoNormal"><u class=""></u>&nbsp;<u class=""></u></p>
<div class=""><p class="MsoNormal">On Mon, Feb 29, 2016 at 10:53 AM, Abaci B &lt;<a href="mailto:abaci64@gmail.com" target="_blank" class="">abaci64@gmail.com</a>&gt; wrote:<u class=""></u><u class=""></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" class="">
<div class=""><p class="MsoNormal">That's exactly what I noticed, it breaks out of the current function, why not open a Jira? I don't think it's supposed to behave this way.<u class=""></u><u class=""></u></p>
</div>
<div class="">
<div class="">
<div class=""><p class="MsoNormal"><u class=""></u>&nbsp;<u class=""></u></p>
<div class=""><p class="MsoNormal">On Mon, Feb 29, 2016 at 1:37 AM, Andrew Keil &lt;<a href="mailto:andrew.keil@visytel.com" target="_blank" class="">andrew.keil@visytel.com</a>&gt; wrote:<u class=""></u><u class=""></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" class="">
<div class="">
<div class=""><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">Thanks for your response.</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">&nbsp;</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">I have gone through these with no luck. &nbsp;&nbsp;Like I said the session:destroy(“…”) crashes FreeSWITCH, which is therefore
 off the list.&nbsp; The rest simply interrupt the current function and do no end the script.</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">&nbsp;</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">I guess my next move is to see why session:destroy() crashes FreeSWITCH, however I am a little snowed under at the
 moment so if anyone has some time to replicate this (only needs one line of code in a Lua script) and pass this on to the developers that would be great.</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">&nbsp;</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">Andrew</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><a name="1430673312_183271413_-69840466_-1874271269__MailEndCompose" class=""><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">&nbsp;</span></a><u class=""></u><u class=""></u></p><p class="MsoNormal"><b class=""><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif" class="">
<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank" class="">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank" class="">freeswitch-users-bounces@lists.freeswitch.org</a>]
<b class="">On Behalf Of </b>Abaci B<br class="">
<b class="">Sent:</b> Saturday, 27 February 2016 1:29 AM<br class="">
<b class="">To:</b> FreeSWITCH Users Help &lt;<a href="mailto:freeswitch-users@lists.freeswitch.org" target="_blank" class="">freeswitch-users@lists.freeswitch.org</a>&gt;<br class="">
<b class="">Subject:</b> Re: [Freeswitch-users] Re- End Lua script after HangupHook handled without all the extra code to handle the return to the function</span><u class=""></u><u class=""></u></p>
<div class="">
<div class=""><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p>
<div class=""><p class="MsoNormal">See
<a href="https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAPIReference-session:setHangupHook" target="_blank" class="">
https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAPIReference-session:setHangupHook</a> for a few ways to exit the lua script (error(), return "exit", return "die", s:destroy("error message")). I personally tried return "exit" but it
 seems to me that it only exits the calling function, haven't had a chance to look further, it's possible that the calling it from the within a function is different. if you play around and figure out please report back.<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p>
<div class=""><p class="MsoNormal">On Thu, Feb 25, 2016 at 9:33 PM, Andrew Keil &lt;<a href="mailto:andrew.keil@visytel.com" target="_blank" class="">andrew.keil@visytel.com</a>&gt; wrote:<u class=""></u><u class=""></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt" class="">
<div class="">
<div class=""><p class="MsoNormal">To FreeSWITCH Users,<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">See below for a sample template for a Lua Service Script running inside FreeSWITCH.<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">The issue I have is fairly straightforward.<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">I need a function to run when hangup is detected (ie. at the end of the call) however I understand this must not delay ending the script.&nbsp; This function is CleanUp().&nbsp; Then I would
 like the service to end.<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">The problem I am having is if the caller hangs up during the playback of “intro.wav” (as shown inside the MainService() function below), then the code jumps to the myHangupHook
 which calls CleanUp() perfectly, the issue is once CleanUp() is complete I would like the Lua script to end there and then (ie. at the bottom of CleanUp()).&nbsp; What actually happens is it returns to MainService() and continues to try and play “info.wav”, unless
 I either check for session:ready() everywhere or add a goto as shown below under each streamFile() function call.<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">My aim is to reduce extra code and to make the Lua script simpler and easier to read.&nbsp; Also I would like to try and avoid goto statements, which I know can be done with if (session:ready())
 etc….<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">So is there a way to stop a Lua script running inside FreeSWITCH cleanly?&nbsp; I have tried the os.exit() this is barred from use by FreeSWITCH.&nbsp; I have also tried session:destroy()
 which crashes FreeSWITCH (version 1.6.5 on CentOS 6.7, CentOS 7 and windows) 100% of the time!<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">I could look further into the Lua additions done by the FreeSWITCH team in the source code, however if someone has already solved this then that would be the best solution.<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">FYI: Obviously the script below is simple, however I am sure that you understand if the script was complicated having to use “<b class="">if (session:ready()) then ….”</b> or “<b class="">if (not
 session:ready()) then goto HANGUPEXIT end”</b> makes the code ugly.<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">Thanks in advance,<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">Andrew Keil<u class=""></u><u class=""></u></p><p class="MsoNormal"><b class="">Visytel Pty Ltd</b><u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">------------------------------------------------------------------------------&nbsp; Sample Lua Service -----------------------------------------------------------------------<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">-- Lua template for FreeSWITCH service<u class=""></u><u class=""></u></p><p class="MsoNormal">-- By: Andrew Keil (Visytel Pty Ltd)<u class=""></u><u class=""></u></p><p class="MsoNormal">-- Email:
<a href="mailto:support@visytel.com" target="_blank" class="">support@visytel.com</a> <u class=""></u>
<u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">-- Setup script wide variables here<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">function PreAnswer()<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; freeswitch.consoleLog("INFO", "PRE ANSWER SECTION\n");<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Add your pre answer code from here<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- End of your pre answer code<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; freeswitch.consoleLog("INFO", "PRE ANSWER SECTION COMPLETE\n");&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">function AnswerCaller()<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session:answer()<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session:sleep(1000)<u class=""></u><u class=""></u></p><p class="MsoNormal">end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">function MainService()<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION\n");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (session:ready()) then<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Note (1): If you wish to end the call then simply use: goto ENDSERVICE<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Note (2): To terminate the service sooner when HANGUP is detected use: if (not session:ready()) then goto HANGUPEXIT end<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Add your main service code from here&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (caller would have been answered)<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session:streamFile("intro.wav")<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (not session:ready()) then goto HANGUPEXIT end<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session:streamFile("info.wav")<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (not session:ready()) then goto HANGUPEXIT end<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session:streamFile("outro.wav")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (not session:ready()) then goto HANGUPEXIT end<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- End of your main service code
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ::ENDSERVICE::<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (session:ready()) then<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- End of service so hangup<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session:hangup()&nbsp; -- Should automatically jump to CleanUp() via hangup handler if caller still online at this stage<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto END<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ::HANGUPEXIT::<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; freeswitch.consoleLog("INFO", "END OF SERVICE (HANGUP DETECTED)\n");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ::END::&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; freeswitch.consoleLog("INFO", "MAIN SERVICE SECTION COMPLETE\n");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">end<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">function CleanUp()<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; freeswitch.consoleLog("INFO", "CLEANUP SECTION\n");
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Add your cleanup code from here (caller would have been disconnected)<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- End of your cleanup code<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; freeswitch.consoleLog("INFO", "CLEANUP SECTION COMPLETE\n");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">function myHangupHook(s, status, arg)<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session:hangup()<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CleanUp() -- Run CleanUp function now since the caller has disconnected<u class=""></u><u class=""></u></p><p class="MsoNormal">end<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">-- Setup Hangup event handler here<u class=""></u><u class=""></u></p><p class="MsoNormal">v_hangup = "HANGUP"<u class=""></u><u class=""></u></p><p class="MsoNormal">session:setHangupHook("myHangupHook", "v_hangup")<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">-- Call service functions in order<u class=""></u><u class=""></u></p><p class="MsoNormal">PreAnswer()<u class=""></u><u class=""></u></p><p class="MsoNormal">AnswerCaller()<u class=""></u><u class=""></u></p><p class="MsoNormal">MainService()<u class=""></u><u class=""></u></p><p class="MsoNormal">-- End of Lua service<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p>
</div>
</div><p class="MsoNormal"><br class="">
_________________________________________________________________________<br class="">
Professional FreeSWITCH Consulting Services:<br class="">
<a href="mailto:consulting@freeswitch.org" target="_blank" class="">consulting@freeswitch.org</a><br class="">
<a href="http://www.freeswitchsolutions.com/" target="_blank" class="">http://www.freeswitchsolutions.com</a><br class="">
<br class="">
Official FreeSWITCH Sites<br class="">
<a href="http://www.freeswitch.org/" target="_blank" class="">http://www.freeswitch.org</a><br class="">
<a href="http://confluence.freeswitch.org/" target="_blank" class="">http://confluence.freeswitch.org</a><br class="">
<a href="http://www.cluecon.com/" target="_blank" class="">http://www.cluecon.com</a><br class="">
<br class="">
FreeSWITCH-users mailing list<br class="">
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank" class="">FreeSWITCH-users@lists.freeswitch.org</a><br class="">
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank" class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br class="">
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank" class="">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br class="">
<a href="http://www.freeswitch.org/" target="_blank" class="">http://www.freeswitch.org</a><u class=""></u><u class=""></u></p>
</blockquote>
</div><p class="MsoNormal">&nbsp;<u class=""></u><u class=""></u></p>
</div>
</div>
</div>
</div>
</div><p class="MsoNormal"><br class="">
_________________________________________________________________________<br class="">
Professional FreeSWITCH Consulting Services:<br class="">
<a href="mailto:consulting@freeswitch.org" target="_blank" class="">consulting@freeswitch.org</a><br class="">
<a href="http://www.freeswitchsolutions.com/" target="_blank" class="">http://www.freeswitchsolutions.com</a><br class="">
<br class="">
Official FreeSWITCH Sites<br class="">
<a href="http://www.freeswitch.org/" target="_blank" class="">http://www.freeswitch.org</a><br class="">
<a href="http://confluence.freeswitch.org/" target="_blank" class="">http://confluence.freeswitch.org</a><br class="">
<a href="http://www.cluecon.com/" target="_blank" class="">http://www.cluecon.com</a><br class="">
<br class="">
FreeSWITCH-users mailing list<br class="">
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank" class="">FreeSWITCH-users@lists.freeswitch.org</a><br class="">
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank" class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br class="">
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank" class="">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br class="">
<a href="http://www.freeswitch.org/" target="_blank" class="">http://www.freeswitch.org</a><u class=""></u><u class=""></u></p>
</blockquote>
</div><p class="MsoNormal"><u class=""></u>&nbsp;<u class=""></u></p>
</div>
</div>
</div>
</blockquote>
</div><p class="MsoNormal"><u class=""></u>&nbsp;<u class=""></u></p>
</div>
</div></div><div class=""><br class="webkit-block-placeholder"></div></div>
</div>

<br class="">_________________________________________________________________________<br class="">
Professional FreeSWITCH Consulting Services:<br class="">
<a href="mailto:consulting@freeswitch.org" target="_blank" class="">consulting@freeswitch.org</a><br class="">
<a href="http://www.freeswitchsolutions.com/" rel="noreferrer" target="_blank" class="">http://www.freeswitchsolutions.com</a><br class="">
<br class="">
Official FreeSWITCH Sites<br class="">
<a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank" class="">http://www.freeswitch.org</a><br class="">
<a href="http://confluence.freeswitch.org/" rel="noreferrer" target="_blank" class="">http://confluence.freeswitch.org</a><br class="">
<a href="http://www.cluecon.com/" rel="noreferrer" target="_blank" class="">http://www.cluecon.com</a><br class="">
<br class="">
FreeSWITCH-users mailing list<br class="">
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank" class="">FreeSWITCH-users@lists.freeswitch.org</a><br class="">
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" rel="noreferrer" target="_blank" class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br class="">
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank" class="">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br class="">
<a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank" class="">http://www.freeswitch.org</a><br class=""></blockquote></div><br class=""></div>
<br class="">_________________________________________________________________________<br class="">
Professional FreeSWITCH Consulting Services:<br class="">
<a href="mailto:consulting@freeswitch.org" class="">consulting@freeswitch.org</a><br class="">
<a href="http://www.freeswitchsolutions.com/" rel="noreferrer" target="_blank" class="">http://www.freeswitchsolutions.com</a><br class="">
<br class="">
Official FreeSWITCH Sites<br class="">
<a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank" class="">http://www.freeswitch.org</a><br class="">
<a href="http://confluence.freeswitch.org/" rel="noreferrer" target="_blank" class="">http://confluence.freeswitch.org</a><br class="">
<a href="http://www.cluecon.com/" rel="noreferrer" target="_blank" class="">http://www.cluecon.com</a><br class="">
<br class="">
FreeSWITCH-users mailing list<br class="">
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" class="">FreeSWITCH-users@lists.freeswitch.org</a><br class="">
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" rel="noreferrer" target="_blank" class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br class="">
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" rel="noreferrer" target="_blank" class="">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br class="">
<a href="http://www.freeswitch.org/" rel="noreferrer" target="_blank" class="">http://www.freeswitch.org</a><br class=""></blockquote></div><br class=""></div>
_________________________________________________________________________<br class="">Professional FreeSWITCH Consulting Services: <br class=""><a href="mailto:consulting@freeswitch.org" class="">consulting@freeswitch.org</a><br class="">http://www.freeswitchsolutions.com<br class=""><br class="">Official FreeSWITCH Sites<br class="">http://www.freeswitch.org<br class="">http://confluence.freeswitch.org<br class="">http://www.cluecon.com<br class=""><br class="">FreeSWITCH-users mailing list<br class="">FreeSWITCH-users@lists.freeswitch.org<br class="">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users<br class="">UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users<br class="">http://www.freeswitch.org</div></blockquote></div><br class=""></div></body></html>