Jump to content
Gold Sponsor: Data-Way IT-Consulting, Austria

  • IsRedirectionLoopConfigured()

    IsRedirectionLoopConfigured()

    Lua   → VBScript

     

    This function returns true if the current script user has an unconditional redirection to a user configured, where the current call already has been (in his call routing).

    Please see the Introduction chapter for some usage instructions.

     

    ------------------------------------------------------------------  
    -- IsRedirectionLoopConfigured 
    --  
    -- Checks if the undonditional redirection target of the script user is
    -- already in the PreviousScripts list, i.e. the call was previously already in that user's call routing.
    --
    -- Parameter:
    --
    -- Return:
    --   boolean 
    ------------------------------------------------------------------
    function IsRedirectionLoopConfigured()
        PBXScript.OutputTrace ("-------------> IsRedirectionLoopConfigured")
    
        local bReturn = false
    
        if PBXUser.UnconditionalRedirect() then
    
            local sRedirectToUser = GetUserNameFromExtension(PBXUser.UnconditionalRedirectNumber())
            local tScripts = nil
    
            tScripts = PBXScript.PreviousScripts()
            if (tScripts ~= nil) then
                for i = 1, #tScripts do
        
                    PBXScript.OutputTrace ("PreviousScript.username = " .. tScripts[i].username)
        
                    if (tScripts[i].username == sRedirectToUser) then
                        PBXScript.OutputTrace ("Found redirection target in the PreviousScripts list. So this is most likely a loop!")
                        bReturn = true
                    end
                    
                end
            end
        end
    
        PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn))
        PBXScript.OutputTrace ("<------------- IsRedirectionLoopConfigured")
    
        return bReturn
    end

     

    This function makes use of the function GetUserNameFromExtension() to get the username of the destination the current script user has an unconditional redirection configured to. Afterwards it uses the Server Script API function PBXScript.PreviousScripts() to search the username in the list of previous call routing scripts. 

     

    Once this function returns true the idea is to disabled the unconditional redirection to prevent a loop.

     

    if IsRedirectionLoopConfigured() then
        PBXUser.UnconditionalRedirect(false)
    end

     

     

    There is another function IsLoopConfigured() available, following another approach to identify an existing call loop.

     

    Please take a look into the How to avoid loops topic for more details.
     

    This function was converted from VBScript into Lua from the initially posted version in this forum topic.
     

     


    Tom Wellige
     Share


     Share




    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.