[Freeswitch-users] LUA Callback - Help

Michael Collins msc at freeswitch.org
Thu Jun 10 10:33:59 PDT 2010


You do realize that you don't even need Lua to accomplish what you want to
do, right? Instead of launching "luarun callback.lua ${caller_id_number}" as
your API you can just do an originate:

<action application="set" data="api_hangup_hook=originate
{ignore_early_media=true}
sofia/gateway/
voipms/1${caller_id_number} 12345 XML default"/>

Create an extension 12345 (or pick a different number) and have the dialplan
apps in that extension do all the stuff you are trying to do. Example:

<extension name="callback_stuff">
  <condition field="destination_number" expression="^(12345)$">
    <action application="sleep" data="500"/>
    <action application="set" inline="true"
data="message_dir=/usr/local/freeswitch/sounds/en/us/callie/custom/callback/"/>
    <!-- Now do whatever you were going to do
         By the looks of your script you want the caller to enter some
digits
         Then you probably wanted to transfer the caller to that destination
         You can use play-and-get-digits for this
         Please see the wiki because I can't do any more work on this right
now-
           my 3 year old son just jumped on my lap and is making me break
his two
           Pop Tarts into little pieces and he wants to type and eat...
    -->
  </condition>
</extension>

Remember the golden rule: Use the dialplan wherever possible because it will
always be more efficient than a scripting language. (BTW, when the FS book
comes out you'll see more about this topic.)

HTH and happy dialing!
-MC

2010/6/10 Aloysius Lloyd <lloyd.aloysius at sunteltech.ca>

> Thanks Vitalli.
>
> Increase the short delay solve the problem. I increase from 1000 to 2000.
>
> But when I answer the phone there is a silent before play the file because
> of the dealy.
>
> How to improve this? Is there any setting to make the session fast.
>
>
> Thanks
> Lloyd
>
>
> 2010/6/10 Vitalii Colosov <vetali100 at gmail.com>
>
>> Try to add short delay - session:sleep:
>>
>> ...
>> session:setAutoHangup(false);
>>
>> session:sleep(1000);
>> ...
>>
>> Sometimes I was getting session is not ready, and fixed this by adding
>> short delay.
>>
>> Maybe you have same problem here.
>>
>> Regards,
>> Vitalie
>>
>>
>>
>> 10 июня 2010 г. 16:20 пользователь Aloysius Lloyd <
>> lloyd.aloysius at sunteltech.ca> написал:
>>
>> VItalli,
>>>
>>> I try your suggestion. Now the script look like this
>>>
>>>
>>> os.execute("sleep " .. tonumber(10));
>>>
>>> pin_number_test="0511";
>>> out_gateway1="sofia/gateway/voipms/1";
>>> message_dir="/usr/local/freeswitch/sounds/en/us/callie/custom/callback/";
>>>
>>> number_to_call= argv[1];
>>>
>>> session =
>>> freeswitch.Session("{ignore_early_media=true,originate_timeout=40}"..out_gateway1..number_to_call);
>>> session:setAutoHangup(false);
>>>
>>> if ( session:ready() ) then
>>>         session:sleep(1000);
>>>          if (session:answered()) then
>>>                 session:sleep(1000);
>>>                 session:streamFile(message_dir.."enter-dest.wav");
>>>          end
>>> end
>>>
>>>  ===
>>>
>>> Also I try 5 test . This time out of 5 test,  wave file play only one
>>> time. Other for 4 tests silent.
>>>
>>> Thanks
>>> Lloyd
>>>
>>>
>>>
>>> 2010/6/10 Vitalii Colosov <vetali100 at gmail.com>
>>>
>>> It looks OK what you wrote - we have almost same lua code.
>>>>
>>>> The only thing that I have in addition in my script is "if
>>>>  (session:answered())" construction.
>>>>
>>>> Try to write it like this:
>>>> ...
>>>>
>>>> if ( session:ready() ) then
>>>>         session:sleep(1000);
>>>>         if (session:answered()) then
>>>>            session:sleep(1000);
>>>>             session:streamFile(message_dir.."enter-dest.wav");
>>>>         end
>>>>
>>>> end
>>>> ...
>>>>
>>>> Not sure why this should work and that does not, but this is how it
>>>> works for me - worth trying at lest.
>>>>
>>>>
>>>> Regards,
>>>> Vitalie
>>>>
>>>>
>>>> 10 июня 2010 г. 9:07 пользователь Aloysius Lloyd <
>>>> lloyd.aloysius at sunteltech.ca> написал:
>>>>
>>>>
>>>>> without bypass_media_after_bridge=true same results.
>>>>>
>>>>> Lloyd
>>>>>
>>>>>
>>>>>
>>>>> 2010/6/10 Aloysius Lloyd <lloyd.aloysius at sunteltech.ca>
>>>>>
>>>>> I try the bypass_media_after_bridge=true  .. same results.
>>>>>>
>>>>>> Thanks
>>>>>> Lloyd
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thu, Jun 10, 2010 at 2:00 AM, Sergey Scheglov <sid at eltc.ru> wrote:
>>>>>>
>>>>>>> В Thu, 10 Jun 2010 01:26:51 -0400
>>>>>>> Aloysius Lloyd <lloyd.aloysius at gmail.com> wrote:
>>>>>>>
>>>>>>>
>>>>>>> > session =
>>>>>>> >
>>>>>>> freeswitch.Session("{bypass_media_after_bridge=true,ignore_early_media=true,originate_timeout=40}"..out_gateway1..number_to_call);
>>>>>>> > session:setAutoHangup(false);
>>>>>>> >
>>>>>>> > Thanks
>>>>>>> > Lloyd
>>>>>>>
>>>>>>> Try without bypass_media_after_bridge=true
>>>>>>>
>>>>>>> Regard
>>>>>>> Sergey Scheglov
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> 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
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>>
>>>
>>> _______________________________________________
>>> 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
>>>
>>>
>>
>> _______________________________________________
>> 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
>>
>>
>
> _______________________________________________
> 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/20100610/c267e384/attachment-0001.html 


More information about the FreeSWITCH-users mailing list