cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1537
Views
35
Helpful
7
Replies

Cisco Finesse Javascript Team Collection Handlers

Hello,

I'm building a Finesse gadget to display the agents of a team with there current assigned attributes. I want the gadget to display only the agents that are actually logged on and I want to update de gadget dynamically when an agent of the team logs on or off.

To accomplish this I'm trying to use the Team handlers onLoad and onChange and also the Collection handlers onLoad, onCollectionAdd and onCollectionDelete. However, I cannot get this to work. Finesse does not respond to any update within the team. I have an agent logged on and the gadget shows correctly, so onLoad handler does work fine. However, when another agent from the team logs on or off, the gadget does not update. 

If I do some testing with the User handlers onLoad and onChange, it works perfectly fine.

Also, when I call the method 'team.refresh(1);' the gadget updates fine, following the onChange handler of the team object. 

Here is my code, can anyone point me in the right direction? 

 

_getAllAgents = function(team) {


clientLogs.log("teamHandlerAdded");

team.getUsers({
onLoad: _showGadget,
onCollectionAdd: _userAdded
});
};



init : function () {

<omitted code> team = new finesse.restservices.Team({ id: cfg.teamId, onLoad: _getAllAgents, onChange: _userAdded });

team.addHandler('change', _getAllAgents);
<omitted code> }

Thanks a lot!

 

Regards, Martijn

1 Accepted Solution

Accepted Solutions

Hi,

 

After trying this out myself, I realized I had a typo in the topic. It should be:

 


handleUserLoad = function (userevent) { // Get an instance of the dialogs collection and register handlers for dialog additions and // removals dialogs = user.getDialogs( { onCollectionAdd : handleNewDialog, onCollectionDelete : handleEndDialog }); finesse.clientservices.ClientServices.subscribe('finesse.api.Team.<teamId>.Users', _onTeamChange); }, _onTeamChange = function (userevent) { clientLogs.log("On Team Change"); },

(Remember to change the <teamId> to the actual id)

 

When using the browser's debugger, it seems like the userevent isn't a predefined object and is raw data. You should use the debugger tool to figure out how to parse the information.

 

P.S. I realize that documentation needs some updating.

 

Thanx,

Denise

View solution in original post

7 Replies 7

dekwan
Cisco Employee
Cisco Employee

Hi,

 

Off the top of my head without doing any verification, you have to use the finesse.restservices.Team constructor (https://developer.cisco.com/docs/finesse/#!rest-services-team/methods) which you have done. When an agent changes state, the onChange handler (_userAdded in your case) will be triggered. The reason for this is that the Team object holds a list of ALL agents no matter what their state is. So when they change the state (log in, log out, ready, etc), it is just updating the state of that agent.

 

Have you looked to see if the _userAdded handler gets triggered?

 

Thanx,

Denise

Hi,

 

Thanks for your response. Yes, I have checked if the _userAdded handler gets triggered and it does not. 

 

I might know why, by now. I think Finesse does not act on Team notifications by default. A subscription to team updates is required first (by default only user, dialogs. media and systeminfo notifications are handled).

But I'm still figuring how to subscribe to the notification service to receive team updates. I suppose it has to be done in the Javascript, but I cannot find how. Played around a little with gadgets.Hub.subscribe(), but cannot get it working yet.

 

Any ideas how this is supposed to be done?

Hi,

 

Correct, a supervisor is not automatically subscribed to the Team notifications. Also, this can only be done for Supervisors and not agents.

 

I haven't done this in a really long time so again, I'm saying this from memory and didn't verify, but I think it is:

finesse.clientservices.ClientServices.subscribe('finesse.api.User.' + teamId + '.Users', handler);
One thing you might want to do is watch the client logs in the browser console and see if the supervisor is getting the events. If they are, this is not the issue. If not, then you need to subscribe.
 
Thanx,
Denise

Hi,

I've added this to the code, but no still nothing happens when the notification comes in. I cannot fine any information about this method finesse.clientservices.ClientServices.subscribe() in the Finesse Javascript API documentation.

I changed my code and it looks like this now:

 

_teamChange = function(team) {
		clientLogs.log("_teamChange");
		
		team.getUsers({
			onLoad: _showGadget,
			onCollectionAdd: _showGadget
		});
	};
	
_teamLoad = function(team) {
		
	clientLogs.log("_teamLoad");
		
	finesse.clientservices.ClientServices.subscribe('finesse.api.User.5049.Users', _teamChange);
		
	team.addHandler('change', _teamChange);
		
	team.getUsers({
		onLoad: _showGadget,
		onCollectionAdd: _showGadget
		
	});
		
};

handleUserChange = async function (user) {
        		
	clientLogs.log("Log 1 handleUserChange()");
};
	
handleUserLoad = async function (user) {
       clientLogs.log("Log 1 handleUserLoad()");
	
	team = new finesse.restservices.Team({
			id: cfg.teamId,
			onLoad: _teamLoad,
			onChange: _teamChange
		});
			
};
	
	

return {
       /**
         * Performs all initialization for this gadget
         */
        init : function () {
            cfg = finesse.gadget.Config;
            _util = finesse.utilities.Utilities;

            clientLogs = finesse.cslogger.ClientLogger;  // declare clientLogs

            // Initiate the ClientServices and load the user object. ClientServices are
            // initialized with a reference to the current configuration.
            finesse.clientservices.ClientServices.init(cfg, false);
			
            // Initiate the ClientLogs. The gadget id will be logged as a part of the message
            clientLogs.init(gadgets.Hub, "lkcreskillgadget");
			
			
            // Create a user object for this user (Call GET User)
            user = new finesse.restservices.User({
				id: cfg.id, 
				onLoad : handleUserLoad,
				onChange : handleUserChange
            });
			
					
										
            
            // Initiate the ContainerServices and add a handler for when the tab is visible
            // to adjust the height of this gadget in case the tab was not visible
            // when the html was rendered (adjustHeight only works when tab is visible)
            containerServices = finesse.containerservices.ContainerServices.init();
            containerServices.addHandler(finesse.containerservices.ContainerServices.Topics.ACTIVE_TAB, function() {
                clientLogs.log("Gadget is now visible");  // log to Finesse logger
                // Automatically adjust the height of the gadget to show the html
                gadgets.window.adjustHeight();
            });
            containerServices.makeActiveTabReq();
        }
    };	

 

 

 

Further information: 

- from the browserlogs I can see that the CallControl gadget does subscribe to the teamnode (whether I'm logged on as agent or as supervisor)

CallControl : [ClientServices] MasterPublisher._subscribeNode() - Attempting to subscribe to node '/finesse/api/Team/5049/Users'
CallControl : [ClientServices] MasterPublisher._subscribeNode() - Subscribed to node '/finesse/api/Team/5049/Users'

- I can also see the notification soming in:

CallControl : [ClientServices] MasterPublisher._parseAndPublishXMLEvent() - Received XML event on node '/finesse/api/Team/5049/Users': <Update>
  <data>
    <user>
      <dialogs>/finesse/api/User/15004/Dialogs</dialogs>
      <extension>15004</extension>
      <firstName>XXXXX</firstName>
      <lastName>XXXXX</lastName>
      <loginId>15004</loginId>
      <mediaType>1</mediaType>
      <pendingState></pendingState>
      <state>NOT_READY</state>
      <stateChangeTime>2022-01-10T11:11:13.820Z</stateChangeTime>
      <uri>/finesse/api/User/15004</uri>
      <wrapUpTimer>-1</wrapUpTimer>
    </user>
  </data>
  <event>PUT</event>
  <requestId>78dcad49-33b4-4d29-b2d2-89618140b83c</requestId>
  <source>/finesse/api/User/15004</source>
</Update>

On the gadget I'm developing, nothing happens when the notification comes in. 

Any other ideas?

 

Thanks.

Hi,

 

After trying this out myself, I realized I had a typo in the topic. It should be:

 


handleUserLoad = function (userevent) { // Get an instance of the dialogs collection and register handlers for dialog additions and // removals dialogs = user.getDialogs( { onCollectionAdd : handleNewDialog, onCollectionDelete : handleEndDialog }); finesse.clientservices.ClientServices.subscribe('finesse.api.Team.<teamId>.Users', _onTeamChange); }, _onTeamChange = function (userevent) { clientLogs.log("On Team Change"); },

(Remember to change the <teamId> to the actual id)

 

When using the browser's debugger, it seems like the userevent isn't a predefined object and is raw data. You should use the debugger tool to figure out how to parse the information.

 

P.S. I realize that documentation needs some updating.

 

Thanx,

Denise

Thanks a lot, Denise! The typo was the actual issue. Using the correct parameter now for the subscribe and it works perfectly fine. Should have noticed it myself...

jozefnad
Level 1
Level 1

did you solve how to handle collectionAdd and collectionDelete on team users dialogs?