getUserById(userId) method

Retrieves the user instance by the specified user ID, or null if the user does not exist. It can only be used after the webclient successfully connected.

Parameters

userId: It is a mandatory string parameter. The ID of the user.

Returns

user: Type: user. A User class instance or null if the user does not exist.

Method usage example

In this example we subscribe to the onConnectionStateChanged event. When it fires, the connectionStateChanged function is called, which gets the current status as a parameter. If this status is "ACCESS_GRANTED", we get the first assigned device of the admin user. Then create a call obbject and initiate the call. After it, we subscribe the onCallStateChanged event. When the state of the call changes to "ANSWERED", we send the "Hello World!" message to the admin's extension. (Code example 1).

OzWebClient.onConnectionStateChanged(connectionStateChanged);

function connectionStateChanged(status)
{
    console.log(status);
    if(status.State == ConnectionState.ACCESS_GRANTED)
    {   
		var devices = OzWebClient.helper.getUserById('admin');
		var firstDevice = devices.devices[0];

		newCall = OzWebClient.createCall(firstDevice);
		newCall.start();
		newCall.onCallStateChanged(callStateChanged); 	
	}
}

function callStateChanged(state){
	if (newCall.getCallState() == CallState.ANSWERED){
		newCall.sendMessage("Hello World!");
	}
}
	
Code example 1 - getUserById(userId) method example

More information