Blogs
Our community blogs
-
- 19
entries - 9
comments - 9301
views
Recent Entries
Latest Entry
#19: We are many
Yesterday I was asked an intersting call routing question: is it possible to route a call to different groups, depending on the amount of users currently logged in into one of those groups?
More precisely: if in Group A are more than one users logged in, route all incoming calls to this group. If there is no or just one user logged in, route the call to Group B.
So the question that needs be answered is how many users are currently logged in into a given group?
With a little bit of scripting code this can be answered quickly.
The Server Script API (VBS/Lua) provides a function PBXConfig.GetUserByAddress (VBS/Lua) which can be used to enumerate all users of a group. Per user a set of properties is available:
- UserID
- Name
- EMailAddress
- State
- Numbers
- NumberOfNewVoicemails
The State property is the current state of this user. This is a numeric property and can hold any of the following values:
-
User state not available
UserStateUnavailable = 0
-
User is logged off
UserStateLoggedOff = 1
-
User is logged on
UserStateLoggedOn = 2
-
User is speaking, at least one call has an external origination or destination
UserStateSpeakingExternal = 3
-
A call is currently alerting at one of the user's devices
UserStateAlerting = 4
-
User is speaking, none of the calls has an external origination or destination
UserStateSpeakingInternal = 5
-
User is away (since SwyxWare 2011)
UserStateAway = 6
-
User has do not disturb status (since SwyxWare 2011)
UserStateDoNotDisturb = 7
-
Busy indication from external presence source (e.g. MS Teams) (since SwyxWare 13)
UserStateActive3rdParty = 8
Any number above 1 indicates that the user is logged on (regardless if he is free, busy, away, etc.).
So what is needed to do is to count all users in the group who have a State value above 1.
The following is a simple function that sums all such users up and returns the sum.
VBScript
'------------------------------------------------------------------- ' NumberOfLoggedInUsersInGroup ' ' Returns the number of users which are currently logged in into the given group. ' The users need to have a higher status as "1", i.e. being logged in (regardless if free or busy). ' ' Parameter: ' sGroup name or number of group ' ' return value: ' integer number of logged in users '-------------------------------------------------------------------- Function NumberOfLoggedInUsersInGroup ( sGroup ) PBXScript.OutputTrace("-------------> NumberOfLoggedInUsersInGroup ( sGroup = " & sGroup & " )") Dim nReturn nReturn = 0 Dim Users Set Users = g_PBXConfig.GetUserByAddress(sGroup) Dim User For Each User In Users PBXScript.OutputTrace("Found user " & User.Name & " with current state " & User.State) If User.State > 1 Then nReturn = nReturn + 1 Next NumberOfLoggedInUsersInGroup = nReturn PBXScript.OutputTrace("nReturn = " & nReturn) PBXScript.OutputTrace("<------------- NumberOfLoggedInUsersInGroup") End Function
Lua
------------------------------------------------------------------ -- NumberOfLoggedInUsersInGroup -- -- Returns the number of users which are currently logged in into the given group. -- The users need to have a higher status as "1", i.e. being logged in (regardless if free or busy). -- -- Parameter: -- sNumber uname or number of group -- -- Return: -- integer number of logged in users ------------------------------------------------------------------ function NumberOfLoggedInUsersInGroup( sGroup ) PBXScript.OutputTrace ("-------------> NumberOfLoggedInUsersInGroup ( sGroup = " .. sGroup .. " )") local nReturn = 0 local oUsers = nil oUsers = PBXScript.GetUserByAddress(sGroup) if (oUsers ~= nil) then for i = 1, #oUsers do PBXScript.OutputTrace ("Found user '" .. oUsers[i]:Name() .. "' with current state '" .. oUsers[i]:State() .. "'") if (oUsers[i]:State() > 1) then nReturn = nReturn + 1 end end PBXScript.OutputTrace ("nReturn = " .. tostring(nReturn)) PBXScript.OutputTrace ("<------------- NumberOfLoggedInUsersInGroup") return bReturn end
With placing this code into the Start block of a GSE script (as explained here (VBS) or here (Lua)) it is possible to use an Evaluate block to define a simple condition for routing the calls like needed:
- NumberOfLoggedInUsersInGroup("Group A") > 1
The entire GSE script could then look like this:
The above given function is also part of the Function Collection here on the forum page:
- Function Collection (VBScript) - NumberOfLoggedInUsersInGroup
- Function Collection (Lua) - NumberOfLoggedInUsersInGroup
Enjoy!
PS: don't miss to take a look into the ECR Useful Link Collection.
- Read more...
-
- 0 comments
- 19
-
This post sums this great article series up. Mirjam spent quite some time to identify all those tips and to publish them here on Swyx Forum.
As the article series dates some years back there had been a couple of articles I have not re-posted again, simply because they were not valid with a current SwyxWare version anymore.
But the vast majority of the tips is still valid with current SwyxWare versions and that's why I decided to re-post them to make them available again after the old Swyx Forum went offline.
Thank you very much Mirjam for all your efforts!
- Read more...
-
- 0 comments
-
- 6
entries - 44
comments - 3436
views
Recent Entries
Latest Entry
Call Parking / Open Hold
A common feature request I have had over the years is a Call Park feature, and the usual stock reply to Can Swyx Do..... is NO! but...... of course this is software and anything is possible. I have seen a number of ways of implementing a call park feature some really clever ones that use the conference bridge facility in Swyx to some not so clever ones using analog adaptors to have live logged on extensions which are used to pick up from... sudu call park.
Before I saw the conference room version written by Tom I had a go myself and came up with this solution a couple of years ago and put it online. Recently a couple of requests came in for the source code so I thought I would upload it here.
This is another illustration of how different solutions to problems can be developed with Swyx, there is no right or wrong way, they either work or don't.So next time someone asks if "Swyx can do ......... ?", reply "No it can't, but you can" 🙂
- 6
-
- 9
entries - 0
comments - 3080
views
Recent Entries
- 9