JavaScript API - User
The JavaScript user API can be used to tag a user for instance with data from an existing application that requires authentication and to find the status of a user using the API.
User tagging
Users can be tagged using as in the following example:
CV.user.tag({
"id": "john.doe",
"email": "john.doe@chatvisor.com",
"firstname": "John",
"lastname": "Doe",
"gender": "male",
"assignedUser": "mary.doe@company.com",
"labels": [
"nice", "handsome"
],
"additionalTaggingData": {
"title": "Dr.",
"occupation": "Marketing Director"
}
"externalToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMiJ9.QOIr8fJb3DwDNjREBvm8oxdojUuBKbPLgtv1pBs-yIw"
})
Parameter | Type |
---|---|
value | ActiveUser |
All fields are optional and can be set according to the information available in the customer application.
ActiveUser object
Property | Type | Description |
---|---|---|
id | string | External Id for matching (e.g. username) |
email | string | E-Mail address of the user |
firstname | string | First name of the user |
lastname | string | Last name of the user |
gender | string | Gender of the user. Possible values are "male", "female", "other" or "none" |
labels | string[] | Tags associated with the user (e.g. user group, user id) |
assignedUser | string | The agent this user will be automatically assigned to |
additionalTaggingData | object | A key value object of additional information that will be sent to external sources (like Parloa). Property names of the ActiveUser object like f.e. email or gender are not allowed as keys and will be ignored. To delete a field again you can set it to null . |
externalToken | string | A token that might verify the user by external sources (like Parloa) |
List of active users
This method requires an user token
To get the list of active users with tags that are currently available inside the application the CV.user.list
method can be used. A callback function need to be supplied to this method. If the client is authenticated using a user token only assigned users are returned.
CV.user.list(callbackFn)
Parameter | Type |
---|---|
callbackFn | (ActiveUserResult[]) => void |
The callback function is then called with the result array as the first argument. The objects inside the array are of the following format:
{
"id": "john.doe",
"email": "john.doe@chatvisor.com",
"firstname": "John",
"lastname": "Doe"
"labels": [
"nice", "handsome"
],
"visitorId": "C0487B22C1967D21D25A8465D27999D5F262951B"
}
ActiveUserResult object
The ActiveUserResult
object extends the ActiveUser
object with the following properties:
Property | Type | Description |
---|---|---|
visitorId | string | Unique visitor id of this user (i.e. to start a screensharing call) |
Status of single user
This method requires an user token
To request the status of an single user that may or may not is available inside the application the CV.user.status
method can be called. As the first argument the value of any field in the tag object can be supplied. As the second argument a callback function needs to be provided that will be called with a single result object (same as in the result of CV.user.list
) or null if no matching user is found.
In the following example we search for a user by an e-mail address:
CV.user.status("john.doe@chatvisor.com", callbackFn)
Parameter | Type |
---|---|
searchString | string |
callbackFn | (ActiveUserResult) => void |
Reset visitor
In the case that a user signs in during a single browser session, the user would be overwritten when CV.user.tag
is called for the second time after login. This can be prevented by calling CV.user.reset
. This assigns a new visitor id to the browser session and a new user will be created when calling the tag method.
CV.user.reset()