Search code examples
audioluasipfreeswitch

how to make outgoing call from freeswitch and play file after destination answer call?


I want to write a web app that connects to freeswitch and makes outgoing call to some destination number (gateway for landline or internal sip devices) and plays some sounds (may be do some logic in lua script).

After reading freeswitch wiki, I found originate command but it doesn't work for me (I just test for internal sip number - sofia/internal/username@ip ). If originate command can do this, how to use it properly? If there is another way please tell me.


Solution

  • one way that I test and it work is run a lua script from freeswitch console or ESL:(ex "luarun test.lua")

    https://freeswitch.org/confluence/display/FREESWITCH/Lua+API+Reference#LuaAPIReference-session:hangupCause

    obSession = freeswitch.Session("sofia/192.168.0.4/1002")
     
       -- Check to see if the call was answered
       if obSession:ready() then
        -- Play file here
       else   
        -- This means the call was not answered ... Check for the reason
        local obCause = obSession:hangupCause()
        freeswitch.consoleLog("info", "obSession:hangupCause() = " .. obCause )
        if ( obCause == "USER_BUSY" ) then              -- SIP 486
           -- For BUSY you may reschedule the call for later
        elseif ( obCause == "NO_ANSWER" ) then
           -- Call them back in an hour
        elseif ( obCause == "ORIGINATOR_CANCEL" ) then   -- SIP 487
           -- May need to check for network congestion or problems
        else
           -- Log these issues
        end
        end