VBScript → Lua
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 array 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 array. There shouldn't be any need to modify the ' GetDestinationFromZIPCode function. '---------------------------------------------------------------- Dim ZIP_Code_Areas ' From, To, Destination ZIP_Code_Areas = Array( _ Array(10000, 19999, "101"), _ Array(20000, 29999, "102"), _ Array(30000, 39999, "103"), _ Array(40000, 40999, "104"), _ Array(41000, 41999, "105"), _ Array(42000, 42999, "106"), _ Array(43000, 43999, "107"), _ Array(44000, 49999, "108"), _ Array(50000, 89999, "109"), _ Array(90000, 99999, "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 array 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 "-----> GetDestinationFromZIPCode" PBXScript.OutputTrace "sZIPCode = " & sZIPCode PBXScript.OutputTrace "sDefaultDestination = " & sDefaultDestination PBXScript.OutputTrace "nZipCodeLength = " & nZipCodeLength Dim sReturn sReturn = sDefaultDestination If (IsEmpty(sZIPCode)) Or _ (Len(sZIPCode) <> nZipCodeLength) Or _ (Not IsNumeric(sZIPCode)) Then PBXScript.OutputTrace "Invalid ZIP code, using default destination." PBXScript.OutputTrace "Must be a string constisting of " & nZipCodeLength & " digits (0-9) only." Else Dim bFound, nZIPCode, i bFound = False nZIPCode = CLng(sZIPCode) For i = LBound(ZIP_Code_Areas, 1) to UBound(ZIP_Code_Areas, 1) If (nZIPCode >= ZIP_Code_Areas(i)(0)) And (nZIPCode <= ZIP_Code_Areas(i)(1)) Then PBXScript.OutputTrace "Found ZIP code range " & i+1 & " (" & ZIP_Code_Areas(i)(0) & "-" & ZIP_Code_Areas(i)(1) & ")" sReturn = ZIP_Code_Areas(i)(2) bFound = True End If Next If Not bFound Then PBXScript.OutputTrace "No ZIP code range found, using default destination." End If End If GetDestinationFromZIPCode = sReturn PBXScript.OutputTrace "sReturn = " & sReturn PBXScript.OutputTrace "<----- GetDestinationFromZIPCode" End Function
This function makes use of the Server Script API functions 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.
Via the following link you can download this simple rule (you need to be logged in to be able to use this link)
An eralier version of this function was posted into this forum topic.
By Tom Wellige
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 accountSign in
Already have an account? Sign in here.
Sign In Now