Basicall I trying to merege two call using bridge functionality. Calling First number after connected to first number calling to second number and once second number is connected trying to merge them using below lua script.
Now I need to pass value of argv[1] and argv[2] via postman using below api link
http://X.X.X.X:8080/txtapi/lua?portal/jal5.lua
as of now it is working for hardcoded value as mentioned in the script but same we have to send dynamic number via api for outbound calling purpose.
Do you have any idea how to achieve the same ?
uuid = 123456789;
dialstr1 = argv[1] Need to pass this from postman in variable—>“sofia/gateway/audiocode/1298XXXXXXXXX”;
dialstr2 = argv[2] Need to pass this from postman in variable—>“sofia/gateway/audiocode/1298XXXXXXXXX”;
max_retriesl1 = 1;
max_retriesl2 = 1;
connected = false;
timeout = 45;
local sessionOneAnswered = false
freeswitch.consoleLog(“notice”, “*********** STARTING Call \n");
freeswitch.consoleLog(“notice”, " DIALING “…dialstr1…” \n");
originate_base1 = “{ignore_early_media=true,originate_timeout=90,hangup_after_bridge=true,uuid=”…uuid…“,leg=1}”;
originate_str1 = originate_base1…dialstr1;
session1 = null;
session2 = null;
session = null;
retries = 0;
ostr = “”;
repeat
retries = retries + 1;
if (retries % 2) then
ostr = originate_str1;
end
freeswitch.consoleLog(“notice”, " Dialing Leg1: " … ostr … " - Try: “…retries…” \n");
session1 = freeswitch.Session(ostr);
local hcause = session1:hangupCause();
freeswitch.consoleLog(“notice”, " Leg1: " … hcause … " - Try: “…retries…” \n");
until not ((hcause == ‘NO_ROUTE_DESTINATION’ or hcause == ‘RECOVERY_ON_TIMER_EXPIRE’ or hcause == ‘INCOMPATIBLE_DESTINATION’ or hcause == ‘CALL_REJECTED’ or hcause == ‘NORMAL_TEMPORARY_FAILURE’) and (retries < max_retriesl1))
if (session1:ready()) then
– log to the console
freeswitch.consoleLog(“notice”, " Leg1 (”…ostr…“) CONNECTED! ***********\n”);
session1:setVariable(“ringback”, “%(2000,4000,440,480)”);
end
for j = 1, 35 do
freeswitch.consoleLog(“info”, “+++++++++++++++++in loop ++++++++++” … j)
freeswitch.msleep(1000)
if session1:answered() then
freeswitch.consoleLog(“info”, “+++++++++++++++++inside if ++++++++++” … j)
sessionOneAnswered = true
break ;
elseif (session1:hangupCause() == "USER_BUSY") then
break ;
end
end
if (sessionOneAnswered) then
session1:setVariable(“ringback”, “%(2000,4000,440,480)”);
session1:setVariable(“RECORD_STEREO”, “true”);
session1:execute(“record_session”, “C:/Users/Administrator/Downloads/recordings/external/”…dialstr1…“.mp3”);
– Create session2
originate_base2 = “{ignore_early_media=true,originate_timeout=90,hangup_after_bridge=true,uuid=”…uuid…“,leg=2}”;
originate_str2 = originate_base2…dialstr2;
ostr2 = originate_str2
freeswitch.consoleLog(“notice”, “*********** Dialing: " … ostr2 … " Try: “…retries…” ***********\n”);
session2 = freeswitch.Session(ostr2, session1);
local hcause = session2:hangupCause();
freeswitch.consoleLog("notice", "*********** Leg2: " .. hcause .. " Try: " .. retries .. " ***********\n");
if (session2:ready()) then
freeswitch.consoleLog("notice", "*********** Leg2 ("..ostr2..") CONNECTED! ***********\n");
freeswitch.bridge(session1, session2);
-- session2 if session1 is over
if (session2:ready()) then
freeswitch.consoleLog("notice", "***********session2 disconnected*********")
session2:hangup();
end
end
-- hangup when done
end
if (session1:ready()) then
freeswitch.consoleLog(“notice”, “**session1 disconnected”)
session1:hangup(); end
–end