[Freeswitch-users] Originating a call from lua with rudimentary error checking

John Wehle john at feith.com
Wed Jun 24 18:12:17 PDT 2009


I have a lua script that originates a call:

  local s = freeswitch.Session (
      "{ignore_early_media=true,origination_caller_id_name=" ..
                   caller .. "}loopback/" .. destination .. "/default/XML")

  s:execute ("sleep", "1000")

  ...

which works fine if a valid number is supplied.  However if
a invalid number is supplied, then the script hits:

  [ERR] switch_cpp.cpp:607 session is not initalized
  [ERR] freeswitch_lua.cpp:102 session is not initalized

What's the recommended way to check if the session constructor was
successful (i.e. the number could be dialed)?

My other option is:

  local s = freeswitch.Session ()

  local r = s:originate (nil,
              "{ignore_early_media=true,origination_caller_id_name=" ..
               caller .. "}loopback/" .. destination .. "/default/XML", 300)

  if r == 1 then
    stream:write ("-ERR call failed\n")
    return
  end

which does handle invalid numbers however there are the minor issues such as:

  a) The documentation seems to strongly discourage using the originate
     method for some reason.

  b) The lua originate method seems to require timeout to be specified
     even though the documentation implies it's optional.

  c) Using this approach causes the message:

     [WARNING] mod_limit.c:576 USAGE: hash [insert|delete]/<realm>/<key>/<val>

     which I have yet to track down.

Thoughts?

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john at feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------





More information about the FreeSWITCH-users mailing list