Advertisement
BoberDiversant

Untitled

Dec 31st, 2019
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. dofile('/usr/share/freeswitch/scripts/lua/libs/jsonlua.lua');
  2.  
  3. local jsonLib = jsonlua();
  4.  
  5. -- returns scenario full parameters or log error then hangup
  6. requestFullScenarioParameters = function(ctsHost, ctsPort, campaignId, callUuid, phone)
  7.     local result = {
  8.         error = false;
  9.         json = nil;
  10.     }
  11.  
  12.     local fullRequest = "http://"..ctsHost..":"..ctsPort.."/incomingCallTask/initForCampaignId?campaignId="..campaignId.."&callUuid="..callUuid.."&phone="..phone.." post"
  13.  
  14.     freeswitch.consoleLog("debug", "performing curl " .. fullRequest);
  15.  
  16.     session:execute("curl", fullRequest);
  17.     local curl_response_code = session:getVariable("curl_response_code");
  18.     if tonumber(curl_response_code) ~= 200 then
  19.         freeswitch.consoleLog("ERR", "only 200 code expected from http api requests, but got " .. curl_response_code .. " for " .. fullRequest);
  20.         result.error=true;
  21.     end
  22.     result.json = session:getVariable("curl_response_data");
  23.     return result;
  24.  end
  25.  
  26.  local campaignId=session:getVariable("sip_h_CampaignId")
  27.  local clientId=session:getVariable("sip_h_ClientId")
  28.  local callTaskServiceHost=session:getVariable("sip_h_CallTaskServiceHost")
  29.  local callTaskServicePort=session:getVariable("sip_h_callTaskServicePort")
  30.  local callerNumber=session:getVariable("sip_h_CallerIdNumber")
  31.  local scenarioResultTopic=session:getVariable("sip_h_ResultTopic")
  32.  local callUuid=session:getVariable("call_uuid")
  33.  local phone=session:getVariable("caller_id_number")
  34.  local SipServlet=session:getVariable("SipServlet")
  35.  
  36.  local result = requestFullScenarioParameters(callTaskServiceHost, callTaskServicePort, campaignId, callUuid, phone);
  37.  if result.error then
  38.     session:hangup();
  39.     return
  40.  end
  41.  
  42.  local scenarioFullParameters=jsonLib.decode(result.json)
  43.  
  44.  local callTaskId = scenarioFullParameters.callTaskId
  45.  freeswitch.consoleLog("INFO", "callTaskId: " .. callTaskId);
  46.  
  47.  local recordingFile = "$${recordings_dir}/"..clientId.."/"..campaignId.."/"..callTaskId..".wav"
  48.  freeswitch.consoleLog("INFO", "start recording to " .. recordingFile);
  49.  session:execute("set", "RECORD_STEREO=true")
  50.  session:execute("record_session", recordingFile);
  51.  
  52.  local sipServletSession = freeswitch.Session("sofia/gateway/"..SipServlet.."/incomingSolutionV3?callTaskServiceHost="..callTaskServiceHost.."&callTaskServicePort="..callTaskServicePort.."&callTaskId="..callTaskId.."&callUuid="..callUuid.."&scenarioResultTopic="..scenarioResultTopic)
  53.  
  54.  freeswitch.consoleLog("info","starting ivr from lua")
  55.  
  56.  freeswitch.bridge(session,  sipServletSession)
  57.  
  58. --  session:execute("stop_record_session", recordingFile);
  59.  
  60.  local bridgeParams="{sip_cid_type=rpid,origination_caller_id_name="..callerNumber..",origination_caller_id_number="..callerNumber.."}"
  61.  local bridgeAfterIvr=sipServletSession:getVariable("sip_bye_h_X-Ivoice-BridgeDestination")
  62.  
  63.  if bridgeAfterIvr == nil then
  64.     freeswitch.consoleLog("INFO","bridgeAfterIvr is nil, hangup")
  65.     session:hangup()
  66.  else
  67.     freeswitch.consoleLog("INFO","bridgeAfterIvr not nil, bridging to " .. bridgeAfterIvr)
  68.     local bridgeAfterIvrSession = freeswitch.Session(bridgeParams..bridgeAfterIvr)
  69.     freeswitch.bridge(session, bridgeAfterIvrSession)
  70.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement