Manage user updates
Update user details and receive events whenever someone updates them.
Requires App Context
To store data about users, you must enable App Context for your app's keyset in the Admin Portal.
Update user details
You can edit the metadata of an existing user with update()
and updateUser()
.
Both of these methods give the same output. The only difference is that you call a given method either on the Chat
(updateUser()
) or the User
(update()
) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the user ID you want to update or not because it's already known.
Method signature
These methods take the following parameters:
-
update()
user.update({
name?: string,
externalId?: string,
profileUrl?: string,
email?: string,
custom?: ObjectCustom,
status?: string,
type?: string
}): Promise<User> -
updateUser()
chat.updateUser(
id: string,
{
name?: string,
externalId?: string,
profileUrl?: string,
email?: string,
custom?: ObjectCustom,
status?: string,
type?: string
}): Promise<User>
Input
Parameter | Type | Required in update() | Required in updateUser() | Default | Description |
---|---|---|---|---|---|
id | string | No | Yes | n/a | Unique user identifier. |
name | string | No | No | n/a | Display name for the user (must not be empty or consist only of whitespace characters). |
externalId | string | No | No | n/a | User's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
profileUrl | string | No | No | n/a | URL of the user's profile picture. |
email | string | No | No | n/a | User's email address. |
custom | ObjectCustom | No | No | n/a | JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the custom property is not recommended in SDKs. |
status | string | No | No | n/a | Tag that lets you categorize your app users by their current state. The tag choice is entirely up to you and depends on your use case. For example, you can use status to mark users in your chat app as invited , active , or archived . |
type | string | No | No | n/a | Tag that lets you categorize your app users by their functional roles. The tag choice is entirely up to you and depends on your use case. For example, you can use type to group users by their roles in your app, such as moderator , player , or support-agent . |
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Output
Type | Description |
---|---|
Promise<User> | Returned object containing the updated user metadata. |
Errors
Whenever the user ID is required, and you try to update the user without providing their ID, you will receive the ID is required
error. If you try to edit a user that doesn't exist, you will receive the User with this ID does not exist
error.
Basic usage
Change the link to the user's support_agent_15
LinkedIn profile to https://www.linkedin.com/mkelly_vp2
.
-
update()
// reference the "user" object
const user = await chat.getUser("support_agent_15")
// invoke the "update()" method on the "user" object
await user.update(
{
custom: {
linkedInUrl: "https://www.linkedin.com/mkelly_vp2"
}
}
) -
updateUser()
// reference the "chat" object and invoke the "updateUser()" method
const user = await chat.updateUser(
"support_agent_15",
{
custom: {
linkedInUrl: "https://www.linkedin.com/mkelly_vp2"
}
}
)
Get user updates
Two methods let you receive updates about users (user IDs) added, edited, or removed on other clients:
streamUpdates()
checks updates on a singleUser
object.streamUpdatesOn()
checks updates on a list ofUser
objects.
Method signature
These methods take the following parameters:
-
streamUpdates()
user.streamUpdates(
callback: (user: User) => unknown
): () => void -
streamUpdatesOn()
static User.streamUpdatesOn(
users: User[],
callback: (users: User[]) => unknown
): () => void
Input
Parameter | Type | Required in streamUpdates() | Required in streamUpdatesOn() | Default | Description |
---|---|---|---|---|---|
users | User[] | No | Yes | n/a | Array of User objects for which you want to get updates. |
callback | n/a | Yes | Yes | n/a | Callback function passed as a parameter to both methods. It defines the custom behavior to be executed when detecting user metadata changes. |
→ user | User | Yes | No | n/a | Returned User object with the updated data. |
→ users | User[] | No | Yes | n/a | Returned array of User objects with the updated data. |
Output
Type | Description |
---|---|
() => void | Function you can call to disconnect (unsubscribe) from the channel and stop receiving objects events. |
Errors
Whenever a list of User
objects is required as a parameter, and you try to get updates on users without specifying their list, you will receive the Cannot stream user updates on an empty list
error.
Basic usage
Get updates on support_agent_15
.
-
streamUpdates()
const user = await chat.getUser("support_agent_15")
user.streamUpdates((user) => {
console.log("Updated user: ", user)
})
Get updates on support_agent_15
and support-manager
.
-
streamUpdatesOn()
const agentUser = await chat.getUser("support_agent_15")
const managerUser = await chat.getUser("support-manager")
User.streamUpdatesOn([agentUser, incidentChannel], (users) => {
console.log("Updated users: ", users)
})
Other examples
Stop listening to updates on support_agent_15
.
-
streamUpdates()
const user = await chat.getUser("support_agent_15")
const stopUpdates = user.streamUpdates(/* handle update callback */)
// after some time...
stopUpdates()
Stop listening to updates on support_agent_15
and support-manager
.
-
streamUpdatesOn()
const agentUser = await chat.getUser("support_agent_15")
const managerUser = await chat.getUser("support-manager")
const stopUpdates = User.streamUpdatesOn([agentUser, incidentChannel], /* handle update callback */)
// after some time...
stopUpdates()