Bobrovozka

Untitled

Apr 22nd, 2021
506
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- check answering time: https://gitlab.ivoice.online/ivoice-platform/call-task-service/merge_requests/76
  2. -- this parameter is set in FreeswitchGateway.originateParameter document
  3. local MachineAnsweringTimeUpToMsec = session:getVariable("machine_answering_time_up_to")
  4.  
  5. if MachineAnsweringTimeUpToMsec == nil then
  6.     freeswitch.consoleLog("INFO", "no machine_answering_time_up_to_passed - ignoring fast answer machine detection")
  7. else
  8.     freeswitch.consoleLog("INFO", "MachineAnsweringTimeUpToMsec = " .. MachineAnsweringTimeUpToMsec)
  9.     MachineAnsweringTimeUpToMsec = tonumber(MachineAnsweringTimeUpToMsec)
  10.     -- if call answered too fast, assume answering machine
  11.     local createdTime = session:getVariable("created_time")
  12.     local answeredTime = session:getVariable("answered_time")
  13.  
  14.     local timeToAnswerMs = (answeredTime - createdTime) / 1000
  15.     freeswitch.consoleLog("INFO", "time to answer, ms = " .. timeToAnswerMs)
  16.     if timeToAnswerMs < MachineAnsweringTimeUpToMsec then
  17.         local answeringMachineReason = "answered_in_timeToAnswerMs=" .. timeToAnswerMs .. "_MachineAnsweringTimeUpToMsec=" .. MachineAnsweringTimeUpToMsec
  18.         freeswitch.consoleLog("INFO", "hangup because answering machine detected: " .. answeringMachineReason)
  19.         session:setVariable("AnsweringMachine", "true")
  20.         session:setVariable("AnsweringMachineReason", answeringMachineReason)
  21.         session:hangup()
  22.         return
  23.     end
  24. end
  25.  
  26. -- init params
  27.  
  28. local Client = session:getVariable("Client")
  29. local Campaign = session:getVariable("Campaign")
  30. local CallTaskId = session:getVariable("CallTaskId")
  31. local CallingSystemCallUuid = session:getVariable("CallingSystemCallUuid")
  32.  
  33. local CallTaskServiceHost = session:getVariable("ScenarioParametersApiHost")
  34. local CallTaskServicePort = session:getVariable("ScenarioParametersApiPort")
  35. local ScenarioResultTopic = session:getVariable("ScenarioResultTopic")
  36.  
  37. local SleepTime = session:getVariable("SleepTime")
  38.  
  39. local callerNumber = session:getVariable("sip_to_user")
  40.  
  41. local SipServlet = session:getVariable("SipServlet")
  42.  
  43. local AmdEnabled = session:getVariable("AmdEnabled")
  44. if AmdEnabled == nil then
  45.     AmdEnabled = false
  46. end
  47.  
  48. --- bridge processing to ss
  49. freeswitch.consoleLog("info", "dispatching request to: " .. SipServlet)
  50.  
  51. local bridgeTo = "sofia/gateway/" .. SipServlet .. "/outgoingSolution?taskId=" .. CallTaskId .. "&amdEnabled=" .. tostring(AmdEnabled) .. "&callUuid=" .. CallingSystemCallUuid .. "&callTaskServiceHost=" .. CallTaskServiceHost .. "&callTaskServicePort=" .. CallTaskServicePort .. "&scenarioResultTopic=" .. ScenarioResultTopic .. "&sleepBeforeScenarioMs=" .. SleepTime
  52.  
  53. freeswitch.consoleLog("info", "bridging to ss: " .. bridgeTo .. "; AmdEnabled = " .. tostring(AmdEnabled))
  54. local sipServletSession = freeswitch.Session(bridgeTo)
  55. freeswitch.bridge(session, sipServletSession)
  56.  
  57. -- local bridgeParams = "{sip_cid_type=rpid,origination_caller_id_name=" .. callerNumber .. ",origination_caller_id_number=" .. callerNumber .. "}"
  58. local bridgeParams = "{sip_cid_type=none}"
  59. local bridgeAfterIvr = sipServletSession:getVariable("sip_bye_h_X-Ivoice-BridgeDestination")
  60. local phone=session:getVariable("caller_id_number")
  61.  
  62. if Campaign == "6009540af961227f554be5c6" then
  63.     freeswitch.consoleLog("INFO","shatalov_napominalka")
  64.     bridgeParams="{sip_cid_type=none,origination_caller_id_name=shatalov_napominalka_"..phone..",sip_h_X-robot_ivoice=shatalov_napominalka_"..phone..",origination_caller_id_number=shatalov_napominalka_"..phone.."}"
  65. elseif Campaign == "60670c373bc0a6000178208f" then
  66.     freeswitch.consoleLog("INFO","pulse_akciya")
  67.     bridgeParams="{sip_cid_type=none,origination_caller_id_name=pulse_akciya_"..phone..",sip_h_X-robot_ivoice=pulse_akciya_"..phone..",origination_caller_id_number=pulse_akciya_"..phone.."}"
  68. elseif Campaign == "60670c563bc0a60001782090" then
  69.     freeswitch.consoleLog("INFO","shatalov_akciya")
  70.     bridgeParams="{sip_cid_type=none,origination_caller_id_name=shatalov_akciya_"..phone..",sip_h_X-robot_ivoice=shatalov_akciya_"..phone..",origination_caller_id_number=shatalov_akciya_"..phone.."}"
  71. else
  72.     freeswitch.consoleLog("ERROR","bridge robot parameter should be provided, it wasn't")
  73.     session:hangup()
  74. end
  75.  
  76. if bridgeAfterIvr == nil then
  77.     freeswitch.consoleLog("INFO", "bridgeAfterIvr is nil, hangup")
  78.     session:hangup()
  79. else
  80.     freeswitch.consoleLog("INFO", "bridgeAfterIvr not nil, bridging to " .. bridgeAfterIvr)
  81.     local bridgeAfterIvrSession = freeswitch.Session(bridgeParams .. bridgeAfterIvr)
  82.     freeswitch.bridge(session, bridgeAfterIvrSession)
  83. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×