[Freeswitch-users] preAnswer call at lua script and then bridge it to another leg

Nikolay Rogoshchenkov nickolayr at gmail.com
Thu May 3 05:25:05 MSD 2012


Thank you so much for your explanations! I will try this.

--
Nikolay


On Wed, May 2, 2012 at 5:26 PM, Michael Collins <msc at freeswitch.org> wrote:

> 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
> "my_dialstring":
>
> session:setVariable('my_dialstring',session_call)
>
> And then let the Lua script exit. Then just add a bridge to your dialplan:
>
> <action application="bridge" data="${my_dialstring}"/>
>
> 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's
> good at and use the dialplan for what it'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.
>
> -MC
>
> On Tue, May 1, 2012 at 8:17 PM, Nikolay Rogoshchenkov <nickolayr at gmail.com
> > wrote:
>
>> Hello,
>>
>> I have a dialplan where I get the incoming call to lua script
>>
>> <extension name="ext_call">
>>  <action application="set" data="hangup_after_bridge=true"/>
>>  <action application="set" data="ignore_early_media=false"/>
>>  <condition field="destination_number" expression="\d{7,}"/>.
>>  <condition field="${sip_from_host}" expression="^(10\.9\.0\.25)$">.
>>  <action application ="lua" data="answer.lua"/>.
>>  </condition>
>> </extension>
>>
>> and then I have answering in answer.lua:
>> ===========================
>> session:preAnswer();
>>
>> [...accessing to DB...]
>>
>> if (session:ready()) then
>>  repeat
>>     index = index + 1;
>>     session_call =
>> string.format("[leg_timeout=30,ignore_early_media=true,hangup_after_bridge=true,origination_caller_id_number="..
>> cid .."]sofia/gateway/%s/%s",gwlist[index],dn);
>>     legB = freeswitch.Session(session_call);
>> until ((hcause == 'USER_BUSY') or (hcause == 'SUCCESS') or (hcause ==
>> 'NO_ANSWER') or (index == #gwlist) or(session:ready() == false))
>>
>> if (legB:ready()) then.
>>     freeswitch.bridge(session, legB)
>> end
>> ===========================
>>
>> 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).
>> Could you please explain, how I can cancel legB right after I got
>> disconnect on legA in this case? Thank you.
>> --
>> Nikolay
>>
>>
>>
>> _________________________________________________________________________
>> Professional FreeSWITCH Consulting Services:
>> consulting at freeswitch.org
>> http://www.freeswitchsolutions.com
>>
>> 
>> 
>>
>> Official FreeSWITCH Sites
>> http://www.freeswitch.org
>> http://wiki.freeswitch.org
>> http://www.cluecon.com
>>
>> FreeSWITCH-users mailing list
>> FreeSWITCH-users at lists.freeswitch.org
>> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
>> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
>> http://www.freeswitch.org
>>
>>
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> 
> 
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120502/e6ed5e42/attachment.html 


Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list