[Freeswitch-users] Question about Lua script: How do I detect when someone picks up the phone?

Michael Collins msc at freeswitch.org
Tue Jan 26 14:49:11 PST 2010


Thanks for your contributions! They are much appreciated.
-MC

On Fri, Jan 22, 2010 at 1:22 PM, Nicolas Brenner <nicolas at medularis.com>wrote:

> No problem, here it is:
>
> - http://wiki.freeswitch.org/wiki/Call_retry_based_on_hangup_cause
>
> It is linked from your reference (
> http://wiki.freeswitch.org/wiki/Mod_lua#More_Samples).
>
> Sorry I didn't do it early, I hadn't seen your email.
>
> I also added another, more complete, example here (also linked):
>
> - http://wiki.freeswitch.org/wiki/Bridging_two_calls_with_retry
>
>
>
> On Thu, Jan 21, 2010 at 7:12 PM, Michael Collins <msc at freeswitch.org>wrote:
>
>>
>>
>> On Thu, Jan 21, 2010 at 3:35 AM, Nicolas Brenner <nicolas at medularis.com>wrote:
>>
>>>
>>> On Wed, Jan 20, 2010 at 7:06 PM, Mike van Lammeren <
>>> mike at van.lammeren.net> wrote:
>>>
>>>> So, I've been reading about early media in the wiki, and have made a
>>>> little progress, which leads to more questions.
>>>>
>>>> I understand now why a call is considered connected before one person
>>>> has picked up the phone. I am also able to get my script to wait for the
>>>> phone to be picked up, by setting the ignore_early_media variable when
>>>> starting a new session, like this:
>>>>
>>>> customerSession =
>>>> freeswitch.Session("{ignore_early_media=true}sofia/gateway/example.com/"
>>>> .. customerPhoneNumber)
>>>>
>>>>
>>>> After that line, the script waits for the other phone to be picked up.
>>>>
>>>> However, now I wonder what to do with calls that don't complete, get
>>>> busy signals, etc.
>>>>
>>>> What do people do in this case? The only related example I can find on
>>>> the web is for a javascript dialer, which doesn't address any of these
>>>> cases.
>>>>
>>>
>>>
>>> I guess it depends on what you want to do. For example I have a lua
>>> script very similar to what you describe, although there is no confirmation
>>> involved. Depending on the hangup cause the session gets, it might try
>>> redialing with a different gateway, try again or just hangup.
>>>
>>> Take a look here http://wiki.freeswitch.org/wiki/Hangup_causes to see
>>> what each hangup cause means. You don't need to have a special case for all
>>> of them, only the ones you are interested in.
>>>
>>> Here's an example in code which retries a call depending on the hangup
>>> cause. It retries max_retries1 times and alternates between 2 different
>>> gateways:
>>>
>>> session1 = null;
>>> max_retries1 = 3;
>>> retries = 0;
>>> ostr = "";
>>> repeat
>>>         retries = retries + 1;
>>>         if (retries % 2) then ostr = originate_str1;
>>>         else ostr = originate_str12; end
>>>         freeswitch.consoleLog("notice", "*********** Dialing Leg1: " ..
>>> ostr .. " - Try: "..retries.." ***********\n");
>>>         session1 = freeswitch.Session(ostr);
>>>         local hcause = session1:hangupCause();
>>>         freeswitch.consoleLog("notice", "*********** Leg1: " .. hcause ..
>>> " - Try: "..retries.." ***********\n");
>>> until not ((hcause == 'NO_ROUTE_DESTINATION' or hcause ==
>>> 'RECOVERY_ON_TIMER_EXPIRE' or hcause == 'INCOMPATIBLE_DESTINATION' or hcause
>>> == 'CALL_REJECTED' or hcause == 'NORMAL_TEMPORARY_FAILURE') and (retries <
>>> max_retriesl1))
>>>
>>>
>>> Note: originate_str1 and originate_str2 are two different dial strings
>>> for 2 different gateways.
>>>
>>>
>> Nicolas,
>>
>> This is really nice. Would you be willing to add this script and a brief
>> explanation to the wiki? You could create a whole new page and just link to
>> it from here: http://wiki.freeswitch.org/wiki/Mod_lua#More_Samples
>>
>> If you have any questions please let me know!
>> -MC
>>
>>
>> _______________________________________________
>> 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/20100126/18627ee0/attachment-0002.html 


More information about the FreeSWITCH-users mailing list