<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div>I'm creating a Lua script for managing different call scenario.</div><div>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.</div><div>I got a request to send different Hangup Cause, so the Customer switch can automatically reroute call to another carrier. Here is the explaination</div><div><br></div><div><br></div><div><b>The scenario is:</b></div><div>All the endpoints are using a Public IP and no NAT is involved in these steps.</div><div><br></div><div>CUSTOMER ------------------&gt; &nbsp; MY_FREESWITCH &nbsp;&nbsp;-----------------&gt; &nbsp; REMOTE_CARRIER</div><div><br></div><div><br></div><div><b>What happen now:</b></div><div>The customer can send calls. On My freeswitch I will route calls based on Dialled Prefix to a Remote Carrier.&nbsp;</div><div>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.</div><div><br></div><div><br></div><div><b>What should be:</b></div><div>If the remote carrier will send me a&nbsp;CALL_REJECTED (isdn 21) I need to send to the remote customer another Hangup Cause for example:&nbsp;NORMAL_CIRCUIT_CONGESTION (isdn 34).</div><div>How to implement that?</div><div>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.</div><div>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 :)</div><div><br></div><div><br></div><div><b>Below there is my Lua script (just the routing part)</b></div><div><br></div><div>Thank you so much!</div><div>Cheers</div><div>Max</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><blockquote type="cite"><div><font class="Apple-style-span" color="#000000" face="Courier">function string.starts(String,Start)</font></div><div><font class="Apple-style-span" color="#000000" face="Courier">&nbsp; &nbsp;return string.sub(String,1,string.len(Start))==Start</font></div><div><font class="Apple-style-span" color="#000000" face="Courier">end</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><br></font></div><div><font class="Apple-style-span" color="#000000" face="Courier">session:execute("set","hangup_after_bridge=true")</font></div><div><font class="Apple-style-span" color="#000000" face="Courier">called_number = session:getVariable("destination_number")</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><br></font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><br></font></div><div><font class="Apple-style-span" color="#000000" face="Courier">while session:answered()==false and session:ready()==true do</font></div><div><span class="Apple-style-span" style="font-family: Courier; white-space: pre; ">        </span></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>if string.starts(called_number, "393") then</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>-- ITALY MOBILE</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>route_dial_string = "sofia/gateway/REMOTE_CARRIER/" ..called_number</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>else</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>-- OTHER DESTINATIONS</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>route_dial_string = "sofia/gateway/OTHER_CARRIER/" ..called_number</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>end</font></div></blockquote><blockquote type="cite"><div><span class="Apple-style-span" style="font-family: Courier; white-space: pre; ">        </span></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>session:execute("bridge",""..route_dial_string.."")</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000" face="Courier">        </font></span></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000" face="Courier">        </font></span></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>-- ATTEMPT TO REMAP RELEASE CAUSE</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>if ( session:getVariable("last_bridge_hangup_cause") == "CALL_REJECTED" ) then</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>session:hangup("NORMAL_CIRCUIT_CONGESTION");</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000" face="Courier">        </font></span></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000" face="Courier">        </font></span></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">        </span>if session:ready()==false then</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><span class="Apple-tab-span" style="white-space:pre">                </span>session:hangup();</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><br></font></div><div><font class="Apple-style-span" color="#000000" face="Courier">&nbsp; &nbsp;</font></div><div><font class="Apple-style-span" color="#000000" face="Courier">end</font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><br></font></div><div><font class="Apple-style-span" color="#000000" face="Courier"><br></font></div><div><font class="Apple-style-span" color="#000000" face="Courier">session:hangup();</font></div><div><font class="Apple-style-span" color="#000000" face="Courier">freeswitch.consoleLog("info", "That's all folks!");</font></div></blockquote></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></body></html>