Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dofile('/usr/share/freeswitch/scripts/lua/libs/jsonlua.lua');
- local jsonLib = jsonlua();
- -- returns scenario full parameters or log error then hangup
- requestFullScenarioParameters = function(ctsHost, ctsPort, campaignId, callUuid, phone)
- local result = {
- error = false;
- json = nil;
- }
- local fullRequest = "http://"..ctsHost..":"..ctsPort.."/incomingCallTask/initForCampaignId?campaignId="..campaignId.."&callUuid="..callUuid.."&phone="..phone.." post"
- freeswitch.consoleLog("debug", "performing curl " .. fullRequest);
- session:execute("curl", fullRequest);
- local curl_response_code = session:getVariable("curl_response_code");
- if tonumber(curl_response_code) ~= 200 then
- freeswitch.consoleLog("ERR", "only 200 code expected from http api requests, but got " .. curl_response_code .. " for " .. fullRequest);
- result.error=true;
- end
- result.json = session:getVariable("curl_response_data");
- return result;
- end
- local campaignId=session:getVariable("sip_h_CampaignId")
- local clientId=session:getVariable("sip_h_ClientId")
- local callTaskServiceHost=session:getVariable("sip_h_CallTaskServiceHost")
- local callTaskServicePort=session:getVariable("sip_h_callTaskServicePort")
- local callerNumber=session:getVariable("sip_h_CallerIdNumber")
- local scenarioResultTopic=session:getVariable("sip_h_ResultTopic")
- local callUuid=session:getVariable("call_uuid")
- local phone=session:getVariable("caller_id_number")
- local SipServlet=session:getVariable("SipServlet")
- local result = requestFullScenarioParameters(callTaskServiceHost, callTaskServicePort, campaignId, callUuid, phone);
- if result.error then
- session:hangup();
- return
- end
- local scenarioFullParameters=jsonLib.decode(result.json)
- local callTaskId = scenarioFullParameters.callTaskId
- freeswitch.consoleLog("INFO", "callTaskId: " .. callTaskId);
- local recordingFile = "$${recordings_dir}/"..clientId.."/"..campaignId.."/"..callTaskId..".wav"
- freeswitch.consoleLog("INFO", "start recording to " .. recordingFile);
- session:execute("set", "RECORD_STEREO=true")
- session:execute("record_session", recordingFile);
- local sipServletSession = freeswitch.Session("sofia/gateway/"..SipServlet.."/incomingSolutionV3?callTaskServiceHost="..callTaskServiceHost.."&callTaskServicePort="..callTaskServicePort.."&callTaskId="..callTaskId.."&callUuid="..callUuid.."&scenarioResultTopic="..scenarioResultTopic)
- freeswitch.consoleLog("info","starting ivr from lua")
- freeswitch.bridge(session, sipServletSession)
- -- session:execute("stop_record_session", recordingFile);
- local bridgeParams="{sip_cid_type=rpid,origination_caller_id_name="..callerNumber..",origination_caller_id_number="..callerNumber.."}"
- local bridgeAfterIvr=sipServletSession:getVariable("sip_bye_h_X-Ivoice-BridgeDestination")
- if bridgeAfterIvr == nil then
- freeswitch.consoleLog("INFO","bridgeAfterIvr is nil, hangup")
- session:hangup()
- else
- freeswitch.consoleLog("INFO","bridgeAfterIvr not nil, bridging to " .. bridgeAfterIvr)
- local bridgeAfterIvrSession = freeswitch.Session(bridgeParams..bridgeAfterIvr)
- freeswitch.bridge(session, bridgeAfterIvrSession)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement