<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" id="owaParaStyle" style="display: none;">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body dir="ltr" fpstyle="1" aria-label="Message body" tabindex="0">
<div name="divtagdefaultwrapper" id="divtagdefaultwrapper" style="font-family: Calibri,Arial,Helvetica,sans-serif;font-size: 12pt;color: #000000;margin: 0;">
Hi Jamie,
<div><br>
</div>
<div>What we have done is add these lines in the dialplan:</div>
<div><br>
</div>
<div><action application="set" data="session_in_hangup_hook=true"/></div>
<div><action application="set" data="api_hangup_hook=lua myscript.lua"/></div>
<div><br>
</div>
<div>Then in <FSROOT>/scripts/myscript.lua:</div>
<div><br>
</div>
<div>cdr_uuid = session:getVariable("cdr_uuid");</div>
<div><br>
</div>
<div>This is on a FreeSWITCH 1.2 box. Hope this helps.</div>
<div><br>
</div>
<div>regards,</div>
<div>David<br>
<div style="color: rgb(40, 40, 40);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> freeswitch-users-bounces@lists.freeswitch.org on behalf of Jaime<br>
<b>Sent:</b> Tuesday, 16 December 2014 13:04<br>
<b>To:</b> freeswitch-users@lists.freeswitch.org<br>
<b>Subject:</b> [Freeswitch-users] Hoot get variables in a LUA Hook Event.</font>
<div> </div>
</div>
<div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">Hello,</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">I’m trying to use the Hook event’s with LUA script’s when the channel Hangup a call,</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">but I’m unable to get the variables, for example uuid, ani or billed seconds for the call,</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">I’m using freeswitch 1.4.13 on Centos 6.6 and my configuration is:</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">In /autoload_configs/lua.conf.xml</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">[…]</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><font face="Calibri,sans-serif"> <hook event="CHANNEL_HANGUP_COMPLETE" script="catch-event-cdr1.lua"/></font></div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">In my catch-event-cdr1.lua script I wrote:</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"> ses = freeswitch.Session();</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">
<div><font face="Calibri,sans-serif"> my_uuid = ses:getVariable("uuid");</font></div>
<div><font face="Calibri,sans-serif"> freeswitch.consoleLog("notice"," uuid=("..my_uuid..")\n")</font></div>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">But I’m get the following error:</div>
<div>
<div><font face="Calibri,sans-serif"> 2014-12-15 23:51:46.100755 [ERR] switch_cpp.cpp:724 session is not initalized</font></div>
<div><font face="Calibri,sans-serif"> 2014-12-15 23:51:46.100755 [NOTICE] switch_cpp.cpp:1328 uuid=()</font></div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">Also, in the wiki doc I see a reference for the “env” Object, (<a href="https://wiki.freeswitch.org/wiki/Mod_lua#Special_Case:_env_object">https://wiki.freeswitch.org/wiki/Mod_lua#Special_Case:_env_object</a>)
but if I call it as the example in the same lua script my result is:</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">How I call the env variable:</div>
<div>
<div><font face="Calibri,sans-serif"> dat = env:serialize()</font></div>
<div><font face="Calibri,sans-serif"> freeswitch.consoleLog("INFO","Here's everything:\n" .. dat .. "\n”)</font></div>
</div>
<div><font face="Calibri,sans-serif"><br>
</font></div>
<div>
<div>And I got the following error:</div>
<div><font face="Calibri,sans-serif"> 2014-12-16 00:00:17.440782 [ERR] mod_lua.cpp:203 /usr/share/freeswitch/scripts/catch-event-reg6.lua:27: attempt to index global 'env' (a nil value)</font></div>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><font face="Calibri,sans-serif">Your help will be appreciated.</font></div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"><br>
</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">—</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">Jamie</div>
<div style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px">Jaimecm@gmail.com</div>
<span id="OLK_SRC_BODY_SECTION" style="color:rgb(0,0,0); font-family:Calibri,sans-serif; font-size:14px"></span></div>
</div>
</div>
</div>
</body>
</html>