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()1user.Update(ChatUserData updatedData);
2
3public class ChatUserData
4{
5 public string Username { get; set; } = string.Empty;
6 public string ExternalId { get; set; } = string.Empty;
7 public string ProfileUrl { get; set; } = string.Empty;
8 public string Email { get; set; } = string.Empty;
9 public string CustomDataJson { get; set; } = string.Empty;
10 public string Status { get; set; } = string.Empty;
11 public string Type { get; set; } = string.Empty;
12} -
UpdateUser()1chat.UpdateUser(
2 string Id,
3 ChatUserData updatedData
4)
5
6public class ChatUserData
7{
8 public string Username { get; set; } = string.Empty;
9 public string ExternalId { get; set; } = string.Empty;
10 public string ProfileUrl { get; set; } = string.Empty;
11 public string Email { get; set; } = string.Empty;
12 public string CustomDataJson { get; set; } = string.Empty;
13 public string Status { get; set; } = string.Empty;
14 public string Type { get; set; } = string.Empty;
15}
Input
| Parameter | Required in Update() | Required in UpdateUser() | Description |
|---|---|---|---|
IdType: stringDefault: n/a | No | Yes | Unique user identifier. |
→ UsernameType: stringDefault: n/a | No | No | Display name for the user (must not be empty or consist only of whitespace characters). |
→ ExternalIdType: stringDefault: n/a | No | No | User's identifier in an external system. You can use it to match Id with a similar identifier from an external database. |
→ ProfileUrlType: stringDefault: n/a | No | No | URL of the user's profile picture. |
→ EmailType: stringDefault: n/a | No | No | User's email address. |
→ CustomDataJsonType: ObjectCustomDefault: n/a | No | No | 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. |
→ StatusType: stringDefault: n/a | No | No | 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. |
→ TypeType: stringDefault: n/a | No | No | 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
Both methods return an awaitable Task.
Sample code
Change the link to the user's support_agent_15 LinkedIn profile to https://www.linkedin.com/mkelly_vp2.
-
Update()1 -
UpdateUser()1
Get user updates
These methods let you receive updates about users (user IDs) added, edited, or removed on other clients:
SetListeningForUpdates()— subscribe the current user to a channel which receives object update information.OnUserUpdated— add a single event handler to a singleUserobject update.AddListenerToUsersUpdate()— add a single event handler to each user update from the provided list.
Method signature
These methods take the following parameters:
-
SetListeningForUpdates()1user.SetListeningForUpdates() -
OnUserUpdated1// event on the user entity
2public event Action<User> OnUserUpdated;
3// needs a corresponding event handler
4void EventHandler(User user) -
AddListenerToUsersUpdate()1chat.AddListenerToUsersUpdate(
2 List<string> userIds,
3 Action<User> listener
4)
Input
| Parameter | Required in SetListeningForUpdates | Required in OnUserUpdated | Required in AddListenerToUsersUpdate() | Description |
|---|---|---|---|---|
listenType: boolDefault: n/a | Yes | n/a | n/a | Whether to listen to User updates. |
userIdsType: List<string>Default: n/a | No | No | Yes | List of user IDs for which you want to get updates. |
listenerType: n/a Default: n/a | No | Yes | Yes | The definition of the custom behavior to be executed when detecting user metadata changes. |
Output
The methods don't return anything.
Sample code
Get updates on support_agent_15.
-
SetListeningForUpdates()andOnUserUpdated1
Get updates on support_agent_15 and support-manager.
-
AddListenerToUsersUpdate()1