Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dofile('/usr/share/freeswitch/scripts/lua/libs/jsonlua.lua');
- dofile('/usr/share/freeswitch/scripts/lua/libs/base64.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 result = requestFullScenarioParameters(callTaskServiceHost, callTaskServicePort, campaignId, callUuid, phone);
- if result.error then
- session:hangup();
- return
- end
- -- freeswitch.consoleLog("INFO", "loaded fullScenarioParameters: " .. result.json);
- local scenarioFullParameters=jsonLib.decode(result.json)
- local callTaskId = scenarioFullParameters.callTaskId
- freeswitch.consoleLog("INFO", "callTaskId: " .. callTaskId);
- local scenarioFullParametersBase64 = encodeBase64(result.json)
- freeswitch.consoleLog("INFO", "scenarioFullParametersBase64: " .. scenarioFullParametersBase64);
- 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/incomingSolutionV2?scenarioFullParametersBase64="..scenarioFullParametersBase64.."&scenarioResultTopic="..scenarioResultTopic)
- freeswitch.consoleLog("info","starting ivr from lua")
- freeswitch.bridge(session, sipServletSession)
- 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