<div class="gmail_extra">Excellent answer, as always :)<br><br><div class="gmail_quote">3 ÍÁÑ 2012šÇ. 1:26 ÐÏÌØÚÏ×ÁÔÅÌØ Michael Collins <span dir="ltr">&lt;<a href="mailto:msc@freeswitch.org" target="_blank">msc@freeswitch.org</a>&gt;</span> ÎÁÐÉÓÁÌ:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The best way to handle this would be to use the bridge application outside of the Lua script. Go ahead and do the Lua script stuff w/ your database and then construct your dialstring. Set that to a channel variable, like &quot;my_dialstring&quot;:<br>

<br><span style="font-family:courier new,monospace">session:setVariable(&#39;my_dialstring&#39;,session_call)</span><br style="font-family:courier new,monospace"><br>And then let the Lua script exit. Then just add a bridge to your dialplan:<br>

<br><span style="font-family:courier new,monospace">&lt;action application=&quot;bridge&quot; data=&quot;${my_dialstring}&quot;/&gt;</span><br style="font-family:courier new,monospace"><br>As a rule of thumb: if you *can* do it in the dialplan then you probably *should* do it in the dialplan. Use the scripting language for what it&#39;s good at and use the dialplan for what it&#39;s good at. Lua is good for logic, db lookups, and more complicated processing. The dialplan is awesome at connecting call legs. The bridge app will do all the work for you so you can focus on more important pursuits. <br>

<br>-MC<br><br><div class="gmail_quote"><div><div class="h5">On Tue, May 1, 2012 at 8:17 PM, Nikolay Rogoshchenkov <span dir="ltr">&lt;<a href="mailto:nickolayr@gmail.com" target="_blank">nickolayr@gmail.com</a>&gt;</span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div>Hello,</div><div><br></div><div>I have a dialplan where I get the incoming call to lua script</div><div><br></div><div>&lt;extension name=&quot;ext_call&quot;&gt;</div><div>š&lt;action application=&quot;set&quot; data=&quot;hangup_after_bridge=true&quot;/&gt;</div>


<div>š&lt;action application=&quot;set&quot; data=&quot;ignore_early_media=false&quot;/&gt;</div><div>š&lt;condition field=&quot;destination_number&quot; expression=&quot;\d{7,}&quot;/&gt;.</div><div>š&lt;condition field=&quot;${sip_from_host}&quot; expression=&quot;^(10\.9\.0\.25)$&quot;&gt;.</div>


<div>š&lt;action application =&quot;lua&quot; data=&quot;answer.lua&quot;/&gt;.</div><div>š&lt;/condition&gt;</div><div>&lt;/extension&gt;</div><div><br></div><div>and then I havešanswering in answer.lua:</div><div>===========================</div>


<div>session:preAnswer();</div><div><br></div><div>[...accessing to DB...]</div><div><br></div><div><div>if (session:ready()) then</div><div>šrepeat</div><div>š š index = index + 1;</div><div>š š session_call = string.format(&quot;[leg_timeout=30,ignore_early_media=true,hangup_after_bridge=true,origination_caller_id_number=&quot;.. cid ..&quot;]sofia/gateway/%s/%s&quot;,gwlist[index],dn);</div>


<div>š š legB = freeswitch.Session(session_call);</div></div>until ((hcause == &#39;USER_BUSY&#39;) or (hcause == &#39;SUCCESS&#39;) or (hcause == &#39;NO_ANSWER&#39;) or (index == #gwlist) or(session:ready() == false))<br>


<br><div><div>if (legB:ready()) then.</div><div>š š freeswitch.bridge(session, legB)</div><div>end</div></div><div>===========================</div><div><br></div><div>But I have a one problem, when the initial legA was disconnected before legB was answered. It itšstillšcontinued što call legB (during theš
leg_timeout).š</div><div>Could you please explain, how I can cancel legB right after I got disconnect on legA in this case? Thank you.</div><div>--<br>Nikolay<br>
<br><br></div>
<br></div></div>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br>
<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br></div>