Hi,I'm creating a Lua script for managing different call scenario.
At the moment I'm stuck with a problem regarding the interoperability between Freeswitch and some potential customer. The problem regards the hangup cause that Freeswitch is sending to their softswitch, to allow a their automatic rerouting based on some Hangup Cause.
I got a request to send different Hangup Cause, so the Customer switch can automatically reroute call to another carrier. Here is the explaination
The scenario is:
All the endpoints are using a Public IP and no NAT is involved in these steps.
CUSTOMER ------------------> MY_FREESWITCH -----------------> REMOTE_CARRIER
What happen now:
The customer can send calls. On My freeswitch I will route calls based on Dialled Prefix to a Remote Carrier.
In my Lua script there is a conditional IF to check for remote disconnect cause, however it seems that the Release Cause is already sent (CALL_REJECTED) when I'm checking with my IF and so, even if the cause has been already sent it's sent again but what "win" is the first hangup sent.
What should be:
If the remote carrier will send me a CALL_REJECTED (isdn 21) I need to send to the remote customer another Hangup Cause for example: NORMAL_CIRCUIT_CONGESTION (isdn 34).
How to implement that?
I can create this remapping using a Diaplan XML configuration, but as I'm using a Lua script to manage the call, I found that is a Lua task to deal with the Hangup Cause, the dialplan rules are ignored.
The "telephony" part of the Lua script is working, what I'm trying to change is the release cause to make my customer happy as with a different release cause he can route traffic correctly and I will not loose my reputation :)
Below there is my Lua script (just the routing part)
Thank you so much!
Cheers
Max
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
session:execute("set","hangup_after_bridge=true")
called_number = session:getVariable("destination_number")
while session:answered()==false and session:ready()==true do
if string.starts(called_number, "393") then
-- ITALY MOBILE
route_dial_string = "sofia/gateway/REMOTE_CARRIER/" ..called_number
else
-- OTHER DESTINATIONS
route_dial_string = "sofia/gateway/OTHER_CARRIER/" ..called_number
end
session:execute("bridge",""..route_dial_string.."")
-- ATTEMPT TO REMAP RELEASE CAUSE
if ( session:getVariable("last_bridge_hangup_cause") == "CALL_REJECTED" ) then
session:hangup("NORMAL_CIRCUIT_CONGESTION");
end
if session:ready()==false then
session:hangup();
end
session:hangup();
freeswitch.consoleLog("info", "That's all folks!");