Call retry based on hangup cause

From FreeSWITCH Wiki
Jump to: navigation, search

Here's a Lua 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_str21 are dial strings for 2 different gateways.

Take a look here 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.