[Freeswitch-users] Lua session disappears after failed call, so hangup cause becomes inaccessable

Bekele Martins bekelemartins at gmail.com
Sun Apr 18 00:37:26 PDT 2010


Hi, I want my lua script to dial a phone number and return back the
disposition code (hangup cause). The problem is if the call fails, the
session variable is destroyed, and the call disposition code is destroyed as
well.

For example:

function make_call()
  sessiondata = "sofia/gateway/myout/15555555555"
  new_session = freeswitch.Session(sessiondata)
  if (new_session:ready()) then
    new_session:streamFile("hello.wav")
    disposition = "ANSWERED"
  else
    disposition = new_session:getVariable("hangup_cause")
    freeswitch.consoleLog("info","Hangup cause = " .. disposition .. "\n")
    disposition = new_session:hangupCause()
    freeswitch.consoleLog("info","Hangup cause = " .. disposition .. "\n")
  end
  return(disposition)
end
make_call()


This returns the following errors:

2010-04-18 03:29:58 [NOTICE] switch_channel.c:602 switch_channel_set_name()
New Channel sofia/external/15555555555
[4bfbb177-2eee-422d-8f2a-5f9d71082254]
2010-04-18 03:30:04 [NOTICE] sofia.c:3597 sofia_handle_sip_i_state() Hangup
sofia/external/15555555555 [CS_CONSUME_MEDIA] [NO_ROUTE_DESTINATION]
API CALL [lua(example.lua)] output:
-ERR encounterd

2010-04-18 03:30:04 [ERR] freeswitch_lua.cpp:102 ready() session is not
initalized
2010-04-18 03:30:04 [ERR] switch_cpp.cpp:600 getVariable() session is not
initalized
2010-04-18 03:30:04 [INFO] switch_cpp.cpp:1122 console_log() Hangup cause =
2010-04-18 03:30:04 [ERR] mod_lua.cpp:182 lua_parse_and_execute()
/usr/local/freeswitch/scripts/example.lua:10: attempt to call method
'hangupCause' (a nil value)
stack traceback:
        /usr/local/freeswitch/scripts/example.lua:10: in function
'make_call'
        /usr/local/freeswitch/scripts/example.lua:16: in main chunk
2010-04-18 03:30:04 [NOTICE] switch_core_session.c:1085
switch_core_session_thread() Session 1 (sofia/external/15555555555) Ended
2010-04-18 03:30:04 [NOTICE] switch_core_session.c:1087
switch_core_session_thread() Close Channel sofia/external/15555555555
[CS_DESTROY]

Is there some way I can accomplish this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20100418/9e3a63ec/attachment.html 


More information about the FreeSWITCH-users mailing list