[Freeswitch-users] Same peace of code works with Javascript and not LUA
Boris Kovalenko
boris at tagnet.ru
Sat Jul 16 17:02:41 MSD 2011
Hello!
Thank You, Anthony. I've updated to the latest git and script is
working now! :)
> your line numbers indicate you are on an old revision update before
> you ask for help
>
> On Fri, Jul 15, 2011 at 12:54 PM, Michael Collins<msc at freeswitch.org> wrote:
>> Okay, turn off the sip trace and turn on debug level logging:
>> sofia global siptrace off
>> console loglevel 7
>> Test call again, pastebin log please.
>> -MC
>>
>> On Fri, Jul 15, 2011 at 10:05 AM, Boris Kovalenko<boris at tagnet.ru> wrote:
>>> :) Nice joke
>>>
>>>
>>> Ok. Pastebin: http://pastebin.freeswitch.org/16818
>>>
>>> The extension is:
>>> <extension name="ext_office_disa2">
>>> <condition field="destination_number"
>>> expression="^(73435230022)$">
>>> <action application="set"
>>> data="disa_msg_enterpin=$${base_dir}/sound
>>> s/ru/RU/elena/ivr/8000/ivr-please_enter_pin_followed_by_pound.wav"/>
>>> <action application="set"
>>> data="disa_msg_wrongpin=$${base_dir}/sound
>>> s/ru/RU/elena/ivr/8000/ivr-pin_or_extension_is-invalid.wav"/>
>>> <action application="set"
>>> data="disa_msg_enterext=$${base_dir}/sound
>>> s/ru/RU/elena/ivr/8000/ivr-enter_ext.wav"/>
>>> <action application="lua" data="common/disa.lua"/>
>>> <!--<action application="javascript" data="common/disa2.js"/>
>>> -->
>>> </condition>
>>> </extension>
>>>
>>>
>>> LUA script:
>>> --[[
>>> ]]
>>>
>>> -- if you choose not to require a pin then then you may want to add a
>>> dialplan c
>>> ondition for a specific caller id
>>> local pin = "111111"; -- make sure to change the PIN number.
>>>
>>> local digitmaxlength = 0;
>>> local initialTimeout = 7500;
>>> local interdigitTimeout = 5000;
>>> local absoluteTimeout = 30000;
>>>
>>> local msg_enterpin;
>>> local msg_wrongPin;
>>> local msg_enterext;
>>>
>>> function disa()
>>> if( not session:ready() ) then
>>> return
>>> end
>>>
>>>
>>> msg_enterpin = session:getVariable("disa_msg_enterpin");
>>> msg_wrongpin = session:getVariable("disa_msg_wrongpin");
>>> msg_enterext = session:getVariable("disa_msg_enterext");
>>>
>>> if( msg_enterpin == nil or msg_wrongpin == nil or msg_enterext == nil
>>> ) then
>>> freeswitch.consoleLog("ALERT", "DISA: Please set necessary
>>> variables");
>>> return false;
>>> end
>>>
>>> session:answer();
>>> session:sleep( 500 );
>>>
>>> -- session:execute("start_dtmf", "");
>>>
>>> if( string.len( pin )> 0 ) then
>>> digitmaxlength = 6;
>>>
>>> session:flushDigits();
>>> digits = session:playAndGetDigits(digitmaxlength, digitmaxlength,
>>> 1, int
>>> erdigitTimeout, "#", msg_enterpin, msg_wrongpin, "\\d+", absoluteTimeout);
>>> freeswitch.consoleLog( "info", "DISA.lua pin: " .. digits .. "\n"
>>> );
>>> end
>>>
>>> if( digits == pin or string.len( pin ) == 0 ) then
>>> local ru_ring = session:getVariable("ru-ring");
>>> local originate_string;
>>>
>>> originate_session = nil;
>>>
>>> session:setVariable("ringback", ru_ring); -- set to
>>> ringto
>>> ne
>>> session:setVariable("transfer_ringback", ru_ring); -- set to
>>> ringto
>>> ne
>>> session:setVariable("hangup_after_bridge", "true");
>>> session:setVariable("v_numbering_plan", "RU");
>>>
>>> digits = ""; -- clear dtmf digits to prepare for next dtmf
>>> request
>>> digitmaxlength = 20;
>>> session:flushDigits();
>>> digits = session:playAndGetDigits(6, digitmaxlength, 1,
>>> interdigitTimeou
>>> t, "#", msg_enterext, "", "\\d+", absoluteTimeout);
>>> if( string.len( digits ) == 0 ) then
>>> return false;
>>> end
>>> freeswitch.consoleLog( "info", "DISA.lua Collected: " .. digits ..
>>> "\n"
>>> );
>>> originate_string =
>>> "{ignore_early_media=true" ..
>>> ",origination_caller_id_number=" ..
>>> session:getVariable("caller_id_n
>>> umber") ..
>>> ",originate_timeout=90" ..
>>> -- ",uuid=" .. session:get_uuid() ..
>>> "}" ..
>>> "sofia/ipbx/" .. session:getVariable("v_ats_srcport") .. "#"
>>> ..
>>> digits .. "@192.168.1.1:5060";
>>>
>>> originate_session = freeswitch.Session( originate_string, session
>>> );
>>>
>>> session:setAutoHangup( false );
>>> originate_session:setAutoHangup( false );
>>>
>>> if( originate_session:ready() ) then
>>>
>>> freeswitch.bridge(session, originate_session);
>>> -- originate_session:hangup();
>>> end
>>> end
>>> end
>>>
>>> local digits = "";
>>>
>>> disa();
>>>
>>> if( session:ready() ) then
>>> session:hangup();
>>> end
>>>
>>>
>>> The extension where originate is placed:
>>> <extension name="ext_domestic_e164">
>>> <condition field="destination_number" expression="^(7[0-9]{10})$">
>>> <action application="log" data="NOTICE [top.ctx] -
>>> ext_domestic"/>
>>> <action application="set" data="hangup_after_bridge=true"/>
>>> <action application="set" data="continue_on_fail=false"/>
>>> <action application="set"
>>> data="failure_causes=USER_BUSY,NO_ANSWER"/>
>>> <action application="set" data="fail_on_single_reject=true"/>
>>> <!-- Least Cost Routing scheme -->
>>> <action application="lcr" data="$1 lcr_tagnet"/>
>>> <action application="set" data="call_timeout=60"/>
>>> <action application="set" data="bridge_answer_timeout=60"/>
>>> <action application="bridge" data="${lcr_auto_route}"/>
>>> <action application="hangup"/>
>>> </condition>
>>> </extension>
>>>
>>> Try harder..
>>>
>>> On Jul 15, 2011 4:43 AM, "Boris Kovalenko"<boris at tagnet.ru> wrote:
>>>> Hello!
>>>>
>>>> I tried, no success.
>>>>
>>>>> after you create it
>>>>>
>>>>> session:setAutoHangup(0)
>>>>>
>>>>> or it will hangup when the script exits
>>>>>
>>>>> On Thu, Jul 14, 2011 at 1:11 PM, Boris Kovalenko<boris at tagnet.ru>
>>>>> wrote:
>>>>>> Hello!
>>>>>>
>>>>>> Here it is http://pastebin.freeswitch.org/16809
>>>>>> Hope somebody help
>>>>>>
>>>>>> get a console log w/ siptrace of that scenario and put it on pastebin.
>>>>>> the
>>>>>> gang here will take a look.
>>>>>> -MC
>>>>>>
>>>>>> On Thu, Jul 14, 2011 at 10:39 AM, Boris Kovalenko<boris at tagnet.ru>
>>>>>> wrote:
>>>>>>> And another problem found. If the remote party answers immediately
>>>>>>> all
>>>>>>> is ok. But if remote waits more then 8-10 seconds before answer - the
>>>>>>> call is dropped when answered. Can't understand where to look for a
>>>>>>> problem.
>>>>>>>> Hello!
>>>>>>>>
>>>>>>>> I found a problem. originate_session must not to be local.
>>>>>>>>> Hello!
>>>>>>>>>
>>>>>>>>> I'm trying to migrate DISA from Javascript to LUA. This peace of
>>>>>>>>> code works fine in Javascript:
>>>>>>>>>
>>>>>>>>> ostr = "{ignore_early_media=true" +
>>>>>>>>> ",origination_caller_id_number=" +
>>>>>>>>> session.getVariable("caller_id_number") +
>>>>>>>>> "}sofia/ipbx/50004#" + digits +
>>>>>>>>> "@192.168.1.1:5060";
>>>>>>>>> osession = new Session( ostr );
>>>>>>>>> bridge(session, osession);
>>>>>>>>> osession.hangup();
>>>>>>>>>
>>>>>>>>> With LUA not:
>>>>>>>>> originate_string =
>>>>>>>>> "{ignore_early_media=true" ..
>>>>>>>>> ",origination_caller_id_number=" ..
>>>>>>>>> session:getVariable("caller_id_number") ..
>>>>>>>>> "}" ..
>>>>>>>>> "sofia/ipbx/50004#" ..
>>>>>>>>> digits .. "@192.168.1.1:5060";
>>>>>>>>> originate_session = freeswitch.Session( originate_string );
>>>>>>>>> freeswitch.bridge(session, originate_session);
>>>>>>>>> originate_session:hangup();
>>>>>>>>>
>>>>>>>>> The call is droped when remote answers. There is an error in log:
>>>>>>>>> bridge: session not ready. I tried to use
>>>>>>>>> if( originate_session:ready() ) then
>>>>>>>>> freeswitch.bridge(session, originate_session);
>>>>>>>>> originate_session:hangup();
>>>>>>>>> end
>>>>>>>>>
>>>>>>>>> with no luck :(. Please, help me. What am I doing wrong?
>>>>>>>>>
>>>>>>> --
>>>>>>> Regards,
>>>>>>> Boris
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Join us at ClueCon 2011, Aug 9-11, Chicago
>>>>>>> http://www.cluecon.com 877-7-4ACLUE
>>>>>>>
>>>>>>> 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
>>>>>>
>>>>>> _______________________________________________
>>>>>> Join us at ClueCon 2011, Aug 9-11, Chicago
>>>>>> http://www.cluecon.com 877-7-4ACLUE
>>>>>>
>>>>>> 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
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Regards,
>>>>>> Boris
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Join us at ClueCon 2011, Aug 9-11, Chicago
>>>>>> http://www.cluecon.com 877-7-4ACLUE
>>>>>>
>>>>>> 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
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> --
>>>> Regards,
>>>> Boris
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Join us at ClueCon 2011, Aug 9-11, Chicago
>>>> http://www.cluecon.com 877-7-4ACLUE
>>>>
>>>> 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
>>>
>>> _______________________________________________
>>> Join us at ClueCon 2011, Aug 9-11, Chicago
>>> http://www.cluecon.com 877-7-4ACLUE
>>>
>>> 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
>>>
>>>
>>> --
>>> Regards,
>>> Boris
>>>
>>>
>>> _______________________________________________
>>> Join us at ClueCon 2011, Aug 9-11, Chicago
>>> http://www.cluecon.com 877-7-4ACLUE
>>>
>>> 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
>>>
>>
>> _______________________________________________
>> Join us at ClueCon 2011, Aug 9-11, Chicago
>> http://www.cluecon.com 877-7-4ACLUE
>>
>> 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
>>
>>
>
>
--
Regards,
Boris
More information about the FreeSWITCH-users
mailing list