Manage user updates
Update user details and receive events whenever someone updates them.
Requires App Context
Enable App Context in the Admin Portal to store user data.
Update user details
Edit user metadata with Update() or UpdateUser().
Update()- call on aUserobject (no ID needed)UpdateUser()- call on aChatobject (requires user ID)
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
Receive updates when User objects are edited or removed:
StreamUpdates()- monitors a single userStreamUpdatesOn()- monitors multiple users
Both methods subscribe the current user to a channel and add an objects event listener for uuid events.
Change types
For details on ChatEntityChangeType values (Updated and Deleted) and their meaning, see Change types.
Stream update behavior
StreamUpdates()enables listening for updates on a single user. Use theOnUserUpdatedorOnUpdateevents to handle changes.StreamUpdatesOn()has two overloads:StreamUpdatesOn(List<User>, Action<List<User>>)returns the complete list of users you're monitoring each time any change occurs to any of them.StreamUpdatesOn(List<User>, Action<User, ChatEntityChangeType>)returns only the specific user that was updated along with the type of change (UpdatedorDeleted).
Method naming
Earlier versions used SetListeningForUpdates() to enable streaming. This method has been superseded by StreamUpdates(), though it remains available for backward compatibility.
Method signature
These methods take the following parameters:
-
StreamUpdates()1user.StreamUpdates(bool stream) -
OnUserUpdated1// event on the User entity
2public event Action<User> OnUserUpdated;
3// needs a corresponding event handler
4void EventHandler(User user) -
OnUpdate1// event on the User entity
2public event Action<User, ChatEntityChangeType> OnUpdate;
3// needs a corresponding event handler
4void EventHandler(User user, ChatEntityChangeType changeType) -
StreamUpdatesOn()(static) - returns all users1User.StreamUpdatesOn(
2 List<User> users,
3 Action<List<User>> listener
4) -
StreamUpdatesOn()(static) - returns individual user with change type1User.StreamUpdatesOn(
2 List<User> users,
3 Action<User, ChatEntityChangeType> listener
4)
Input
| Parameter | Required in StreamUpdates() | Required in OnUserUpdated / OnUpdate | Required in StreamUpdatesOn() | Description |
|---|---|---|---|---|
streamType: boolDefault: n/a | Yes | n/a | n/a | Whether to start (true) or stop (false) listening to User object updates. |
usersType: List<User>Default: n/a | No | No | Yes | List of User objects for which you want to get updates. |
listenerType: Action<List<User>>Default: n/a | No | No | Yes (first overload) | Callback that receives the complete list of all users being monitored each time any change occurs. |
listenerType: Action<User, ChatEntityChangeType>Default: n/a | No | No | Yes (second overload) | Callback that receives the specific user that was updated and the type of change. |
changeTypeType: ChatEntityChangeTypeDefault: n/a | n/a | No (only in OnUpdate) | No (only in second overload) | Enum indicating the type of change: Updated or Deleted. |
Output
These methods don't return a value. Updates are delivered through event handlers or callback functions.
Sample code
-
StreamUpdates()andOnUserUpdatedGet updates on
support_agent_15.1 -
StreamUpdatesOn()with individual user updatesGet updates on
support-agent-1andsupport-agent-2. The callback receives each updated user individually along with the change type.1