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(ChatUserData updatedData);
public class ChatUserData
{
public string Username { get; set; } = string.Empty;
public string ExternalId { get; set; } = string.Empty;
public string ProfileUrl { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string CustomDataJson { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
} -
UpdateUser()
chat.UpdateUser(
string Id,
ChatUserData updatedData
)
public class ChatUserData
{
public string Username { get; set; } = string.Empty;
public string ExternalId { get; set; } = string.Empty;
public string ProfileUrl { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string CustomDataJson { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
}
Input
Parameter | Type | Required in Update() | Required in UpdateUser() | Default | Description |
---|---|---|---|---|---|
Id | string | No | Yes | n/a | Unique user identifier. |
→ Username | 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. |
→ CustomDataJson | 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
These methods don't return data.
Basic usage
Change the link to the user's support_agent_15
LinkedIn profile to https://www.linkedin.com/mkelly_vp2
.
-
Update()
if (!chat.TryGetUser("user_id", out var user))
{
Console.WriteLine("Couldn't find user!");
return;
};
var updatedUserData = new ChatUserData
{
ProfileUrl = "https://www.linkedin.com/mkelly_vp2"
};
user.Update(updatedUserData); -
UpdateUser()
var updatedUserData = new ChatUserData
{
ProfileUrl = "https://www.linkedin.com/mkelly_vp2"
};
chat.Update("support_agent_15",updatedUserData);
Get user updates
These methods let you receive updates about users (user IDs) added, edited, or removed on other clients:
StartListeningForUpdates()
— subscribe the current user to a channel which receives object update information.OnUserUpdated
— add a single event handler to a singleUser
object update.AddListenerToUsersUpdate()
— add a single event handler to each user update from the provided list.
Method signature
These methods take the following parameters:
-
StartListeningForUpdates()
user.StartListeningForUpdates()
-
OnUserUpdated
// event on the user entity
public event Action<User> OnUserUpdated;
// needs a corresponding event handler
void EventHandler(User user) -
AddListenerToUsersUpdate()
chat.AddListenerToUsersUpdate(
List<string> userIds,
Action<User> listener
)
Input
Parameter | Type | Required in StartListeningForUpdates | Required in OnUserUpdated | Required in AddListenerToUsersUpdate() | Default | Description |
---|---|---|---|---|---|---|
user | User | No | Yes | No | n/a | The user object to handle the update event for. |
userIds | List<string> | No | No | Yes | n/a | List of user IDs for which you want to get updates. |
listener | n/a | No | Yes | Yes | n/a | The definition of the custom behavior to be executed when detecting user metadata changes. |
Output
These methods don't return data.
Basic usage
Get updates on support_agent_15
.
-
StartListeningForUpdates()
andOnUserUpdated
if (!chat.TryGetUser("support_agent_15", out var user))
{
Console.WriteLine("Couldn't find user!");
return;
};
user.StartListeningForUpdates();
user.OnUserUpdated += OnUserUpdatedHandler; // or use lambda
void OnUserUpdatedHandler(User user)
{
Console.WriteLine($"User updated: {user.Id}");
}
Get updates on support_agent_15
and support-manager
.
-
AddListenerToUsersUpdate()
List<string> users = new List<string> { "support_agent_15", "support-manager" };
Action<User> listener = (User user) =>
{
// Print the updated user name
Console.WriteLine("Updated user Name: " + user.Name);
};
chat.AddListenerToUsersUpdate(users, listener);