Jump to content

Tom Wellige

Root Moderator
  • Posts

    4,310
  • Joined

  • Last visited

  • Days Won

    117

 Content Type 

Profiles

SwyxPEDIA Wiki

Zendesk Integration

Persistent Variables

Longest Waiting

VBScript build in functions

GSE build in functions (VBScript)

Server Script API (VBScript)

GSE build in functions (Lua)

Server Script API (Lua)

Function Collection (VBScript)

Function Collection (Lua)

IPS Integration

Jira Service Integration

Forums

Blogs

Downloads

Everything posted by Tom Wellige

  1. Lua SwxWare v13.10 This helper function search the first occurance of a substring within a string an returns its position. local nPos = StringPos(str, substr) This function returns a number value. Example: local nPos = StringPos("Erika Mustermann", "Muster") PBXScript.OutputTrace("nPos = " .. tostring(nPos)) --> nPos = 7
  2. Lua SwxWare v13.10 This helper function checks is a given substring is part of a given string. local bFound = IsInString(str, substr) This function returns a boolean value. Examples: local bFound = IsInString("+494012345", "123") PBXScript.OutputTrace("bFound = " .. tostring(bFound)) --> bFound = true local bFound = IsInString("Erika Mustermann", "Herbert") PBXScript.OutputTrace("bFound = " .. tostring(bFound)) --> bFound = false
  3. Lua SwxWare v13.10 This helper function returns a given number of characters from a given position from within a given string. local sMid = StringMid(str, pos, len) This function returns a string value. Example: local sMid = StringMid("Erika Mustermann", 7, 6) PBXScript.OutputTrace("sMid = " .. sMid) --> sMid = Muster
  4. Lua SwxWare v13.10 This helper function returns the given number of characters from the left side of the given string. local sLeft = StringLeft(str, len) This function returns a string value. Examples: local sLeft = StringLeft("Erika Mustermann", 5) PBXScript.OutputTrace("sLeft = " .. sLeft) --> sLeft = Erika local tConfig = nil local sPublicLineAccess = "" tConfig = PBXScript.GetPBXConfig() sPublicLineAccess = tConfig.publicaccessprefix PBXScript.OutputTrace ("Configured public line access: " .. sPublicLineAccess) -- check forwarding if (PBXUser.UnconditionalRedirect()) then PBXScript.OutputTrace ("Unconditional call forwarding configured to " .. PBXUser.UnconditionalRedirectNumber()) if (StringLeft(PBXUser.UnconditionalRedirectNumber(), StringLen(sPublicLineAccess)) == sPublicLineAccess) then PBXScript.OutputTrace ("External call forwarding configured") bReturn = true else PBXScript.OutputTrace ("Internal call forwarding configured") end else PBXScript.OutputTrace ("No unconditional call forwarding configured") end
  5. Lua SwxWare v13.10 This helper function returns the given number of characters from the right side of the given string. local sRight = StringRight(str, len) This function returns a string value. Example: local sRight = StringRight("Erika Mustermann", 4) PBXScript.OutputTrace("sRight = " .. sRight) --> sRight = mann
  6. Lua SwxWare v13.10 This helper function returns the length of a given string. local nLength = StringLen(str) This function returns a number value. Examples: local nLength = StringLen("Erika Mustermann") PBXScript.OutputTrace("nLength = " .. tostring(nLength)) --> nLength = 16 local tConfig = nil local sPublicLineAccess = "" tConfig = PBXScript.GetPBXConfig() sPublicLineAccess = tConfig.publicaccessprefix PBXScript.OutputTrace ("Configured public line access: " .. sPublicLineAccess) -- check forwarding if (PBXUser.UnconditionalRedirect()) then PBXScript.OutputTrace ("Unconditional call forwarding configured to " .. PBXUser.UnconditionalRedirectNumber()) if (StringLeft(PBXUser.UnconditionalRedirectNumber(), StringLen(sPublicLineAccess)) == sPublicLineAccess) then PBXScript.OutputTrace ("External call forwarding configured") bReturn = true else PBXScript.OutputTrace ("Internal call forwarding configured") end else PBXScript.OutputTrace ("No unconditional call forwarding configured") end
  7. Lua SwxWare v13.10 This helper function checks if the given parameter is of type string. local bString = IsString(str) This function returns a boolean value. Examples: local bString = IsString("I am a string") PBXScript.OutputTrace("bString = " .. tostring(bString)) --> bString = true local bString = IsString(12345) PBXScript.OutputTrace("bString = " .. tostring(bString)) --> bString = false
  8. Lua → VBScript This function logs some details into a given log (text) file. Please see the Introduction chapter for some usage instructions. Please note: the Lua Beta Testing versions of SwyxWare (13.1x) do not limit any file access. In the final release version file access will only be permitted in the SwyxWare CPE (customer premise equipment) version. Within the cloud versions (SDC and SwyxON) file access will not be permitted. local LogFormat = '"#NUMBER#","#NAME#","#TIMESTAMP#"' ------------------------------------------------------------------ -- Function LogCallIntoTextFile -- -- Logs details of the current call into a text file. -- Line format: "Number","Name","Timestamp" -- -- Parameter: -- sFileName name of logfile (incl. path) -- -- Return: -- boolean true - log created, false - error creating log ------------------------------------------------------------------ function LogCallIntoTextFile ( sFileName ) PBXScript.OutputTrace ("-----------> LogCallIntoTextFile ( " .. sFileName .. " )") local bReturn = false local sLine = "" local oFile = io.open(sFileName, "a") -- append mode if oFile then -- create log line sLine = LogFormat sLine = StringReplace(sLine, "#NUMBER#", PBXCall.CallingPartyNumber()) sLine = StringReplace(sLine, "#NAME#", PBXCall.CallingPartyName()) sLine = StringReplace(sLine, "#TIMESTAMP#", PBXUser.Now()) PBXScript.OutputTrace ("sLine = " .. sLine) -- write (append) log data to file oFile:write(sLine) oFile:close() bReturn = true else PBXScript.OutputTrace ("Error opening log file!") end PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn)) PBXScript.OutputTrace ("<----------- LogCallIntoTextFile") return bReturn end This function makes use of the Server Script API functions PBXCall.CallingPartyNumber(), PBXCall.CallingPartyName() and PBXUser.Now() for the call details and PBXScript.OutputTrace to write trace information into the SwyxServer trace file. It also uses the GSE build-in helper function StringReplace() to format the log data. You need to make sure, that the file can be accessed from the call routing script. For this it is necessary, that the Windows users the Swyx Server service is running under (usually SwyxServiceAccount) has at least read privileges on the file. Please note, that you have to escape backslashes in the sFileName parameter. So instead of "C:\Files\logfile.txt" you have to pass "C:\\Files\\logfile.txt".
  9. VBScript This function logs some details into a database Please see the Introduction chapter for some usage instructions. ' CursorTypeEnum Values Const adOpenForwardOnly = 0 Const adOpenKeyset = 1 Const adOpenDynamic = 2 Const adOpenStatic = 3 ' LockTypeEnum Values Const adLockReadOnly = 1 Const adLockPessimistic = 2 Const adLockOptimistic = 3 Const adLockBatchOptimistic = 4 ' CommandTypeEnum Values Const adCmdUnknown = &H0008 Const adCmdText = &H0001 Const adCmdTable = &H0002 Const adCmdStoredProc = &H0004 '---------------------------------------------------------------- ' Function LogCallIntoDatabase ' ' Logs details of the current call into a database. ' ' Parameter: ' ' Return: ' boolean true - log created, false - error creating log '---------------------------------------------------------------- Function LogCallIntoDatabase PBXScript.OutputTrace "-----------> LogCallIntoDatabase" On Error Resume Next Dim bReturn bReturn = False Dim sDsn sDsn = _ "Provider=sqloledb;" & _ "Data Source=***ServerName***;" & _ "Initial Catalog=***DatebaseName***;" & _ "Integrated Security=SSPI" ' open connection to database Dim db Set db = CreateObject("ADODB.Connection") db.Open sDsn if Err <> 0 then PBXScript.OutputTrace "Error opening database!" PBXScript.OutputTrace Err & ": " & Err.Description else ' open recordset Set rs = CreateObject("ADODB.Recordset") rs.Open "Logging", db, adOpenDynamic, adLockOptimistic, adCmdTable if Err <> 0 then PBXScript.OutputTrace "Error creating new dataset!" PBXScript.OutputTrace Err & ": " & Err.Description else rs.AddNew rs("[Number]") = PBXCall.CallingPartyNumber rs("[Name]") = PBXCall.CallingPartyName rs("[TimeStamp]") = Now rs.Update if Err <> 0 then PBXScript.OutputTrace "Error writing new dataset to database!" PBXScript.OutputTrace Err & ": " & Err.Description end if rs.close end if Set rs = Nothing db.close end if Set db = Nothing LogCallIntoDatabase = bReturn PBXScript.OutputTrace "bReturn = " & bReturn PBXScript.OutputTrace "<----------- LogCallIntoDatabase" End Function This function makes use of the Server Script API functions PBXCall.CallingPartyNumber and PBXCall.CallingPartyName for the call details and PBXScript.OutputTrace to write trace information into the SwyxServer trace file. You need to make modifications to this example: Connection String (sDSN) The connection string defines the database and the access privileges you want to use to login into the database. The Connection Strings page gives examples for any kind of database. You should use OLE DB Data Providers, and if possible Trusted Connection instead of Standard Security (username/password) authentication. In this case the Windows user the Swyx Server service is running under (by default this is the "SwyxServiceAccount") needs at least read access to your database. For example, if you want to connect to an MS SQL Server, you select SQL Server from above linked Connection Strings page. Afterwards select Microsoft OLE DB Driver for SQL Server below OLE DB providers. That should bring you here. Logging Table This example assumes a table Logging with the fields Number (nvarchar(255)) Name (nvarchar(255)) TimeStamp (datetime) If your logging table is somehow different you need to modify the function accordingly.
  10. VBScript → Lua This function logs some details into a given log (text) file. Please see the Introduction chapter for some usage instructions. ' FileOpen iomode Values Const fsoForReading = 1 ' Open a file for reading only. Const fsoForWriting = 2 ' Open a file for writing only. Const fsoForAppending = 8 ' Open a file and write to the end of the file. Const fsoDontCreateIfNotExist = False Const fsoCreateIfNotExist = True Const fsoTristateUseDefault = -2 ' Opens the file by using the system default. Const fsoTristateTrue = -1 ' Opens the file as Unicode. Const fsoTristateFalse = 0 ' Opens the file as ASCII. Const LogFormat = """%NUMBER%"",""%NAME%"",""%TIMESTAMP%""" '---------------------------------------------------------------- ' Function LogCallIntoTextFile ' ' Logs details of the current call into a text file. ' Line format: "Number","Name","Timestamp" ' ' Parameter: ' sFileName name of logfile (incl. path) ' ' Return: ' boolean true - log created, false - error creating log '---------------------------------------------------------------- Function LogCallIntoTextFile ( sFileName ) PBXScript.OutputTrace "-----------> LogCallIntoTextFile ( " & sFileName & ")" On Error Resume Next Dim bReturn bReturn = False Dim fso, file, sLine ' create FileSystemObejct Set fso = CreateObject("Scripting.FileSystemObject") ' open text file Set file = fso.OpenTextFile(sFileName, fsoForAppending, fsoCreateIfNotExist, fsoTristateFalse) if Err <> 0 then PBXScript.OutputTrace "Error opening log file!" PBXScript.OutputTrace Err & ": " & Err.Description else ' create log line sLine = LogFormat sLine = Replace(sLine, "%NUMBER%", PBXCall.CallingPartyNumber) sLine = Replace(sLine, "%NAME%", PBXCall.CallingPartyName) sLine = Replace(sLine, "%TIMESTAMP%", Now) PBXScript.OutputTrace "sLine = " & sLine ' write (append) log data to file file.WriteLine(sLine) file.Close() Set file = Nothing bReturn = True end if Set fso = Nothing LogCallIntoTextFile = bReturn PBXScript.OutputTrace "bReturn = " & bReturn PBXScript.OutputTrace "<----------- LogCallIntoTextFile" End Function This function makes use of the Server Script API functions PBXCall.CallingPartyNumber and PBXCall.CallingPartyName for the call details and PBXScript.OutputTrace to write trace information into the SwyxServer trace file.
  11. VBScript This function checks if the current caller (i.e. his phone number) can be found in a configured database. It can be used to create black or white lists for incoming calls on a user. Please see the Introduction chapter for some usage instructions. ' CursorTypeEnum Values Const adOpenForwardOnly = 0 Const adOpenKeyset = 1 Const adOpenDynamic = 2 Const adOpenStatic = 3 ' LockTypeEnum Values Const adLockReadOnly = 1 Const adLockPessimistic = 2 Const adLockOptimistic = 3 Const adLockBatchOptimistic = 4 ' CommandTypeEnum Values Const adCmdUnknown = &H0008 Const adCmdText = &H0001 Const adCmdTable = &H0002 Const adCmdStoredProc = &H0004 '---------------------------------------------------------------- ' CheckCallerInDatabase ' ' Checks if the current callers phone number can be found in database. ' ' Parameter: ' ' Return: ' integer 0 - caller unknown ' 1 - caller known ' 2 - error accessing the database '---------------------------------------------------------------- Function CheckCallerInDatabase PBXScript.OutputTrace "-----------> CheckCallerInDatabase" On Error Resume Next Dim nReturn nReturn = 0 Dim sDsn sDsn = _ "Provider=sqloledb;" & _ "Data Source=***ServerName***;" & _ "Initial Catalog=***DatebaseName***;" & _ "Integrated Security=SSPI" ' open connection to database Dim db Set db = CreateObject("ADODB.Connection") db.Open sDsn if Err <> 0 then PBXScript.OutputTrace "Error opening database!" PBXScript.OutputTrace Err & ": " & Err.Description nReturn = 2 else ' open recordset Dim sSQL Dim rs sSQL = "SELECT * FROM Customers where Phone = '" & PBXCall.CallingPartyNumber & "'" PBXScript.OutputTrace "sSQL = " & sSQL Set rs = CreateObject("ADODB.Recordset") rs.Open sSQL, db, adOpenForwardOnly, adLockReadOnly, adCmdText if Err <> 0 then PBXScript.OutputTrace "Error accessing database!" PBXScript.OutputTrace Err & ": " & Err.Description nReturn = 2 else if not rs.EOF then ' if at least one dataset was found, the caller is known nReturn = 1 PBXScript.OutputTrace "At leat one customer found" else ' if no dataset was found, the caller is not known PBXScript.OutputTrace "No customer found" end if rs.Close end if Set rs = Nothing db.Close end if Set db = Nothing CheckCallerInDatabase = nReturn PBXScript.OutputTrace "nReturn = " & nReturn PBXScript.OutputTrace "<----------- CheckCallerInDatabase" End Function This function makes use of the Server Script API functions PBXCall.CallingPartyNumber to get the callers number and PBXScript.OutputTrace to write trace information into the SwyxServer trace file. You need to make modifications to this example: Connection String (sDSN) The connection string defines the database and the access privileges you want to use to login into the database. The Connection Strings page gives examples for any kind of database. You should use OLE DB Data Providers, and if possible Trusted Connection instead of Standard Security (username/password) authentication. In this case the Windows user the Swyx Server service is running under (by default this is the "SwyxServiceAccount") needs at least read access to your database. For example, if you want to connect to an MS SQL Server, you select SQL Server from above linked Connection Strings page. Afterwards select Microsoft OLE DB Driver for SQL Server below OLE DB providers. That should bring you here. SQL Statement (sSQL) Of course it depends on the structure of your database, how the SQL statement needs to look like. In this simple example it is assumed, that the phone number format which is stored in the database is the same as the one PBXCall.CallingPartyNumber is providing, i.e. the format you see in the display of your SwyxIt! client or IP phone. Things can get much more complicated in real world databases...
  12. Lua → VBScript The following function fills a table with the names of all files in a given folder (incl. subfolders). The names contain the complete path. It can be used for example, to get a list of announcement (.wav) files in a folder to play them one after each other. See example code below... Please see the Introduction chapter for some usage instructions. Please note: the Lua Beta Testing versions of SwyxWare (13.1x) do not limit any file access. In the final release version file access will only be permitted in the SwyxWare CPE (customer premise equipment) version. Within the cloud versions (SDC and SwyxON) file access will not be permitted. ---------------------------------------------------------------- -- GetFilesInFolder() -- -- Reads all file names in given folder (incl. subfolders) into a table. -- -- Parameter: -- sPath name of path -- file filters incl. wildcards "*" and "?" are allowed -- backslashes in the path name need to get escaped -- i.e. C:\\Anouncements\\*.wav -- -- Return: -- table containing all filenames (incl. path) ---------------------------------------------------------------- function GetFilesInFolder ( sPath ) PBXScript.OutputTrace ("-----------> GetFilesInFolder( " .. sPath .. " )") local tFiles = {} local p = io.popen('dir "'.. sPath ..'" /b /s') for sFile in p:lines() do PBXScript.OutputTrace ("sFile = " .. sFile) table.insert(tFiles, sFile) end PBXScript.OutputTrace ("<----------- GetFilesInFolder") return tFiles end This function makes use of the Server Script API function PBXScript.OutputTrace() to write trace information into the SwyxServer trace file. Please note, that you have to escape backslashes in the sFileName parameter. So instead of "C:\Announcements" you have to pass "C:\\Announcements". You can define a filter within the sPath parameter incl. regular wildcards "*" and "?". For example "C:\\Announcements\\*.wav". The following example code can be placed into an Insert Script Code block to play all .wav files in a given folder: local f = GetFilesInFolder("C:\\Announcements\\*.wav") for i = 1, #f do PBXCall.PlayMessage(f[i]) end This exmaple makes use of the Server Script API function PBXCall.PlayMessage() function to play a given .wav file. The .wav files must be in 16kHz, 16bit, PCM, mono format. This function and the example was initially posted in this forum topic.
  13. Lua → VBScript This function checks if the current caller (i.e. his phone number) can be found in a given text file. It can be used to create black or white lists for incoming calls on a user. Please see the Introduction chapter for some usage instructions. Please note: the Lua Beta Testing versions of SwyxWare (13.1x) do not limit any file access. In the final release version file access will only be permitted in the SwyxWare CPE (customer premise equipment) version. Within the cloud versions (SDC and SwyxON) file access will not be permitted. ------------------------------------------------------------------ -- CheckCallerInTextFile -- -- Returns true if the current callers phone number can be found in a given text file. -- The text file must be formatted with one number per line. -- -- Parameter: -- sFileName text file (incl. path) that contains the numbers to check -- backslashes in the filename need to get escaped, i.e. C:\\Files\\List.txt -- -- Return: -- boolean true - number in file, false - number not in file or can't access file ------------------------------------------------------------------ function CheckCallerInTextFile ( sFileName ) PBXScript.OutputTrace ("-----------> CheckCallerInTextFile ( " .. sFileName .. " )") local bReturn = false local sCaller = PBXCall.CallingPartyNumber() PBXScript.OutputTrace ("sCaller = " .. sCaller) local oFile = io.open(sFileName, "r") -- read-only if oFile then io.input(oFile) for sLine in io.lines() do PBXScript.OutputTrace ("sLine = " .. sLine) -- does the number in the text file contain the given number? if IsInString(sCaller, sLine) then PBXScript.OutputTrace ("Found caller in file") bReturn = true end -- does the number in the text file is identical to the given number? --if (sCaller == sLine) then -- PBXScript.OutputTrace ("Found caller in file") -- bReturn = true --end end oFile:close() else PBXScript.OutputTrace ("Can't open file!") end PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn)) PBXScript.OutputTrace ("<----------- CheckCallerInTextFile") return bReturn end This function makes use of the Server Script API functions PBXCall.CallingPartyNumber() to get the callers number and PBXScript.OutputTrace() to write trace information into the SwyxServer trace file. It also uses the GSE build-in helper function IsInString() to find the caller number in the data from the file. You need to make sure, that the file can be accessed from the call routing script. For this it is necessary, that the Windows users the Swyx Server service is running under (usually SwyxServiceAccount) has at least read privileges on the file. Please note, that you have to escape backslashes in the sFileName parameter. So instead of "C:\Files\List.txt" you have to pass "C:\\Files\\List.txt". The function was originally posted into this forum topic.
  14. Auf der Digital X am 13. und 14. September dreht sich wieder alles darum, wie wir gemeinsam die Zukunft von morgen gestalten. Das außergewöhnliche Live-Event macht neueste Technologien erlebbar und bietet eine einzigartige Gelegenheit, um sich zu vernetzen, inspirieren zu lassen und voneinander zu lernen. In über 100 parallel bespielten Locations mit über 300 Partnern und zahlreichen Top-Speakern erweckt die DIGITAL X 2022 im Herzen von Köln die größten Megatrends der Digitalisierung zum Leben. Es erwarten Sie innovative Exponate, zahlreiche Brandhouses, bunte Marktplätze und interaktive Playgrounds sowie ein vielseitiges Indoor- und Outdoor-Bühnenprogramm - Entertainment garantiert! Dabei darf Enreach natürlich nicht fehlen! Als Partner der Deutschen Telekom unterstützen wir die Digital X seit ihrem Start und sind auch 2022 wieder mit dabei. Besuchen Sie uns im Little Link, Maastrichter Str. 20, 50672 Köln, und erfahren Sie, wie Sie mit unseren Lösungen Kommunikation und Zusammenarbeit auf ein neues Level heben können! Weitere Informationen zur Veranstaltung: https://www.digital-x.eu Pressemitteilung auf enreach.de
  15. Grundsätzlich kann man soetwas mittels Call Routing realisieren. Ansatz: mittels Persistenter Variable das Umleitungs Ziel für die Zentrale verwalten. Das Call Routing Script der Zentrale liest den aktuellen Inhalt einer solchen Variable aus. Wenn sie leer ist, dann erfolgt keine Umleitung, ansonsten leitet das Skript den Ruf per Durchstellen Block an das Ziel welches in der Variable gespeichert ist. Auf einem Dummy Benutzer hat man ein Script, welches Ziele in die Variable speichern bzw. ihren Inhalt löschen kann. Die Auswahl, was geschehen soll könnte entweder per DTMF Menü angeboten werden, oder man wählt per Nachwahlziffer in das Skript. Zum Beispiel mit den Ziffern 1 bis 4 um die verschiedenen Ziele zu unterscheiden, oder mit der Ziffer 0 um die Umleitung zu deaktivieren, d.h. den Inhalt der Variable zu löschen. Am Telefon kann man nun Namenstasten definieren, die diesen Dummy Benutzer mit der passenden Nachwahlziffer anrufen. Eine bereits sehr weitgehende Grundlage für diesen Ansatz befindet sich in dem "Night Switch" Beispiel der persistenten Variablen. Das einzige was hiermit nicht möglich ist, ist das BLF am Telefon zu steuern. Hierzu ist mir keine Lösung bekannt.
  16. Mir ist nicht bekannt, dass das SwyxIt! dort eine solche Möglichkeit bietet.
  17. Over the last couple of weeks I have completely reworked then old documentation for VBScript based call routing (Server Script API and GSE build-in functions). The new format is more comfortable to use and also offered me the chance to provide the same kind of documentation for Lua based call routing. The documentation is highly cross-linked, including the possibility to easily switch between VBScript and Lua versions of the current content. The latest addition to the new documentation is the huge usefull Function Collection, that was gathered over the years here in the forum. VBScript based call routing Server Script API GSE build-in functions VBScript build-in functions Function Collection Lua based call routing Server Script API GSE build-in functions Function Collection You will find all these link of course not only here, but also in the page menu (below SwyxPEDIA / Programming References), the SwyxPEDIA page itself and of course the master page for all call routing related stuff: ECR - Useful Link Collection Enjoy!
  18. VBScript Lua After having brought the Server Script API and the GSE build-in function documentation into a new format for VBScript and Lua based call routing, the next logical step was to do the same with the huge function collection from the ECR - Useful Link Collection page. So here you have it: Function Collection (VBScript) Function Collection (Lua) And of course you will find it also easily reachable in the page menu:
  19. VBScript Lua Some time ago I created already a documentation for the Server Script API and GSE build-in functions for VBScript based call routing. With Lua based call routing peeking around the corner I decided to bring this documentation into a new format to be able to differ easily between VBScript and Lua. And of course also created all documentation for Lua based call routing as well. So here you go! VBScript based call routing Server Script API GSE build-in functions Lua based call routing Server Script API GSE build-in functions You can also reach this documentation easily any time via the page menu:
  20. Lua → VBScript This function calls (launches) a given URL (http request) and returns true if the request returns without error. Please see the Introduction chapter for some usage instructions. --------------------------------------------------------------------- -- LaunchHTTPRequest -- -- Launches given URL. -- -- Parameter: -- sURL complete url -- -- return value: -- boolean true - request returned with code 200 -- false - request returned with code <> 200 ---------------------------------------------------------------------- function LaunchHTTPRequest ( sURL ) PBXScript.OutputTrace ("------> LaunchHTTPRequest ( sURL = '" .. sURL .. "' )") local bReturn = false local webreq = require "PBXWebRequest" if (webreq ~= nil) then local hsession, reponseCode hsession = webreq.new() hsession:URL(sURL) hsession:HttpVerb(PBXHttpVerbGet) local vBefore, vAfter, nDuration vBefore = os.time() responseCode = hsession:Execute() vAfter = os.time() nDuration = os.difftime(vAfter, vBefore) PBXScript.OutputTrace("Web request returned after " .. math.floor(nDuration) .. " seconds the response code " .. responseCode) bReturn = (responseCode == 200) end PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn)) PBXScript.OutputTrace ("<------ LaunchHTTPRequest") return bReturn end This function makes use of the Server Script API class PBXWebRequest for the web request and the function PBXScript.OutputTrace() to write trace information into the SwyxServer trace file. This function was converted from VBScript into Lua from the initially posted version in this forum topic.
  21. Lua → VBScript This function returns the current status of the given user. Please see the Introduction chapter for some usage instructions. ------------------------------------------------------------------ -- GetUserStatus -- -- Returns the status of the given user. -- If being used on a user group it returns the status of the last user in the group. -- -- Parameter: -- sNumber extension of user or user group -- -- Return: -- number - PBXUserStateValue -- -- PBXUserStateUnavailable = 0 -- no mutual status signalling configured -- PBXUserStateLoggedOff = 1 -- logged off -- PBXUserStateLoggedOn = 2 -- logged on and free -- PBXUserStateSpeakingExternal = 3 -- busy externally -- PBXUserStateAlerting = 4 -- currently altering/rinbing -- PBXUserStateSpeakingInternal = 5 -- busy internally -- PBXUserStateAway = 6 -- away status active -- PBXUserStateDoNotDisturb = 7 -- do not disturb (DND) status active -- PBXUserStateActive3rdParty = 8 -- busy indication from external presence source (e.g. MS Teams) ------------------------------------------------------------------ function GetUserStatus(sNumber) PBXScript.OutputTrace ("-------------> GetUserStatus(sNumber = " .. sNumber .. ")") local nReturn = 0 local oUsers = nil oUsers = PBXScript.GetUserByAddress(sNumber) if (oUsers ~= nil) then for i = 1, #oUsers do PBXScript.OutputTrace ("Found user " .. oUsers[i]:Name() .. " with current state " .. oUsers[i]:State()) nReturn = oUsers[i]:State() end end PBXScript.OutputTrace ("nReturn = " .. nReturn) PBXScript.OutputTrace ("<------------- GetUserStatus") return nReturn end This function makes use of the Server Script API functions PBXConfig.GetUserByAddress() to resolve the user state and PBXScript.OutputTrace() to write trace information into the SwyxServer trace file. This function was converted from VBScript into Lua from the initially posted version in this forum topic.
  22. Lua → VBScript The following function sets the "new voicemail indication" for a certain user or all users within a user group. Please see the Introduction chapter for some usage instructions. --------------------------------------------------------------------- -- SetNewVoicemailFlag -- -- This function sets the "new voicemail indication" for a single user -- or all users of a SwyxWare user group. -- -- Parameter: -- sUserOrGroup name of user or group -- -- Return: -- none ---------------------------------------------------------------------- function SetNewVoicemailFlag ( sUserOrGroup ) PBXScript.OutputTrace ("-------------> SetNewVoicemailFlag ( sUserOrGroup = " .. sUserOrGroup .. " )") local oUsers = nil oUsers = PBXScript.GetUserByAddress(sUserOrGroup) if (oUsers ~= nil) then for i = 1, #oUsers do PBXScript.OutputTrace ("Found user '" .. oUsers[i]:Name() .. "' with current state '" .. oUsers[i]:State() .. "'") oUsers[i]:NumberOfNewVoicemails(oUsers[i]:NumberOfNewVoicemails() + 1) end end PBXScript.OutputTrace ("<------------- SetNewVoicemailFlag") end This function makes use of the Server Script API functions PBXConfig.GetUserByAddress() to resolve all users in the given group and PBXScript.OutputTrace() to write trace information into the SwyxServer trace file. This function was converted from VBScript into Lua from the initially posted version in this forum topic.
  23. Lua → VBScript This function returns true of the given user is logged off from the server. Please see the Introduction chapter for some usage instructions. ------------------------------------------------------------------ -- IsUserLoggedOff -- -- Checks if given user is logged off -- -- Parameter: -- sNumber user name or extension -- -- Return: -- boolean ------------------------------------------------------------------ function IsUserLoggedOff( sNumber ) PBXScript.OutputTrace ("-------------> IsUserLoggedOff ( sNumber = " .. sNumber .. " )") local bReturn = false local oUsers = nil oUsers = PBXScript.GetUserByAddress(sNumber) if (oUsers ~= nil) then for i = 1, #oUsers do PBXScript.OutputTrace ("Found user '" .. oUsers[i]:Name() .. "' with current state '" .. oUsers[i]:State() .. "'") bReturn = (oUsers[i]:State() == 1) end end PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn)) PBXScript.OutputTrace ("<------------- IsUserLoggedOff") return bReturn end This function makes use of the Server Script API functions PBXConfig.GetUserByAddress() to get the current status of the given user and PBXScript.OutputTrace() to write trace information into the SwyxServer trace file. This function was converted from VBScript into Lua from the initially posted version in this forum topic.
  24. Lua → VBScript This function returns true of the given user is logged on. Please see the Introduction chapter for some usage instructions. ------------------------------------------------------------------ -- IsUserLoggedOn -- -- Checks if given user is logged on -- -- Parameter: -- sNumber user name or extension -- -- Return: -- boolean ------------------------------------------------------------------ function IsUserLoggedOn( sNumber ) PBXScript.OutputTrace ("-------------> IsUserLoggedOn ( sNumber = " .. sNumber .. " )") local bReturn = false local oUsers = nil oUsers = PBXScript.GetUserByAddress(sNumber) if (oUsers ~= nil) then for i = 1, #oUsers do PBXScript.OutputTrace ("Found user '" .. oUsers[i]:Name() .. "' with current state '" .. oUsers[i]:State() .. "'") bReturn = (oUsers[i]:State() >= 2) end end PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn)) PBXScript.OutputTrace ("<------------- IsUserLoggedOn") return bReturn end This function makes use of the Server Script API functions PBXConfig.GetUserByAddress() to get the current status of the given user and PBXScript.OutputTrace() to write trace information into the SwyxServer trace file. This function was converted from VBScript into Lua from the initially posted version in this forum topic.
  25. Lua → VBScript This function checks if the current script user is member of the given group. Please see the Introduction chapter for some usage instructions. ------------------------------------------------------------------ -- IsUserInGroup -- -- Checks if the current script user is in the given group -- -- Parameter: -- sGroup group number or name -- -- Return: -- boolean ------------------------------------------------------------------ function IsUserInGroup ( sGroup ) PBXScript.OutputTrace ("----------> IsUserInGroup ( " .. sGroup .. " )") local bReturn = false local oUsers = nil oUsers = PBXScript.GetUserByAddress(sGroup) if (oUsers ~= nil) then for i = 1, #oUsers do PBXScript.OutputTrace ("Found user '" .. oUsers[i]:Name() .. "'") if (oUsers[i]:Name() == PBXUser.Name()) then PBXScript.OutputTrace ("Current script user '" .. PBXUser.Name() .. "' is member of the group '" .. sGroup .. "'!") bReturn = true end end end PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn)) PBXScript.OutputTrace ("<---------- IsUserInGroup") return bReturn end This function makes use of the Server Script API functions PBXConfig.GetUserByAddress() to resolve all users in the given group and PBXUser.Name() to get the name of the current script user. It also uses PBXScript.OutputTrace() to write trace information into the SwyxServer trace file. This function was converted from VBScript into Lua from the initially posted version in this forum topic.
×
×
  • 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.