Jump to content
  • GetDestinationFromZIPCode()

    GetDestinationFromZIPCode()

    Lua   → VBScript

     

    This function returns a destination to connect a call to related to a given ZIP code.

    Please see the Introduction chapter for some usage instructions.

     

    ------------------------------------------------------------------
    -- ZIP_Code_Areas
    --
    -- This table holds all ZIP code areas (from and to numbers) as
    -- well as the related destination that should be returned by the
    -- GetDestinationFromZIPCode function.
    --
    -- Modifying (add, edit, delete) the ZIP code ranges can easily be 
    -- done in this table. There shouldn't be any need to modify the 
    -- GetDestinationFromZIPCode function.
    ------------------------------------------------------------------
    local ZIP_Code_Areas = 
    {
        { from = 00000, to = 19999, destination = "101" }, 
        { from = 20000, to = 29999, destination = "102" }, 
        { from = 30000, to = 39999, destination = "103" }, 
        { from = 40000, to = 40999, destination = "104" }, 
        { from = 41000, to = 41999, destination = "105" }, 
        { from = 42000, to = 42999, destination = "106" }, 
        { from = 43000, to = 43999, destination = "107" }, 
        { from = 44000, to = 49999, destination = "108" }, 
        { from = 50000, to = 79999, destination = "109" }, 
        { from = 80000, to = 99999, destination = "110" }
    }
    
    
    ------------------------------------------------------------------
    -- GetDestinationFromZIPCode
    --
    -- Returns a destination corresponding to a given ZIP code.
    -- The ZIP code ranges and their destination number are defined in the 
    -- above ZIP_Code_Areas table and can be easily modified there.
    --
    -- If the given ZIP code doesn't match any ZIP code range, the function returns
    -- a default destination.
    --
    -- Parameters
    --   sZIPCode                ZIP code find the destination for
    --   sDefaultDestination     Default destination if no ZIP code range matches the given ZIP code
    --   nZipCodeLength          Length of the used ZIP code. This variy from country to country.
    --
    -- Returns
    --   string                  Destination corresponding to given ZIP code or default destination.
    ------------------------------------------------------------------
    function GetDestinationFromZIPCode ( sZIPCode, sDefaultDestination, nZipCodeLength )
        PBXScript.OutputTrace ("-----------> CheckCallerInTextFile")
        PBXScript.OutputTrace ("sZIPCode = " .. sZIPCode)
        PBXScript.OutputTrace ("sDefaultDestination = " .. sDefaultDestination)
        PBXScript.OutputTrace ("nZipCodeLength = " .. tostring(nZipCodeLength))
    
        local sReturn = sDefaultDestination
    
        if (StringLen(sZIPCode) ~= nZipCodeLength) or (not tonumber(sZIPCode)) then 
    
            PBXScript.OutputTrace ("Invalid ZIP code, using default destination.")
            PBXScript.OutputTrace ("Must be a string constisting of " .. tostring(nZipCodeLength) .. " digits (0-9) only.")
    
        else
    
            local bFound   = false
            local nZIPCode = tonumber(sZIPCode)
    
            for i,range in ipairs(ZIP_Code_Areas) do
    
                if (nZIPCode >= range.from) and (nZIPCode <= range.to) then
                    PBXScript.OutputTrace ("Found ZIP code range " .. tostring(i) .. " (" .. tostring(range.from) .. "-" .. tostring(range.to) .. ")")
                    sReturn = range.destination
                    bFound  = true
                end
    
            end
    
            if not bFound then
                PBXScript.OutputTrace ("No ZIP code range found, using default destination.")
            end
    
        end
    
        PBXScript.OutputTrace ("sReturn = " .. sReturn)
        PBXScript.OutputTrace ("<----- GetDestinationFromZIPCode")
    
        return sReturn
    
    end

     

    This function makes use of the Server Script API function PBXScript.OutputTrace() to write trace information into the SwyxServer trace file.

     

    On top of the code an array is defined which contains ZIP code ranges and a destination. If a given destination is within such a range the function returns the destination being stored for this range.

     

    The idea of this function is, that you ask a user for a ZIP code (Postleitzahl in German) and then connect the call to an agent being responsible for this ZIP code area.

     

    The following is a simple GSE rule showing the usage of this function.

     

    image.png

     

    image.png

     

     

    Via the following link you can download this simple rule (you need to be logged in to be able to use this link)

     

     

    GetDestinationFromZIPCode.rse

     

     

    This function was converted from VBScript into Lua from earlier version of it which was posted in this forum topic.

     

     




    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
×
×
  • 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.