Manage user details

Get details about the app users.

Get user details

Return data about a specific user with the TryGetUser() method.

By default, this method returns all custom user metadata without the need to define that during the call explicitly.

Requires App Context

To store data about users, you must enable App Context for your app's keyset in the Admin Portal.

Method signature

This method takes the following parameters:

chat.TryGetUser(
string userId,
out User user
)

Input

ParameterTypeRequiredDefaultDescription
idstringYesn/aUnique user identifier (up to 92 UTF-8 characters).
userout UserYesn/aThe user to populate with the appropriate User object if the method returns true. If it returns false, the user remains uninitialized.

Output

If the method returns true, the out user parameter is populated with the appropriate User object. If it returns false, the user remains uninitialized.

Basic usage

Get details on user support_agent_15.

if (chat.TryGetUser("support_agent_15", out var user))
{
Console.WriteLine($"Found user with name {user.Name}");
};

Get current user

TryGetCurrentUser is a method that returns the current chat user of the chat app.

Requires App Context

To store data about users, you must enable App Context for your app's keyset in the Admin Portal.

Method signature

This method has the following signature:

chat.TryGetCurrentUser(out User user)

Input

This method doesn't take any parameters.

Output

ParameterTypeDescription
userout UserThe user to populate with the appropriate User object if the method returns true. If it returns false, the user remains uninitialized.

Basic usage

Return the current chat user.

if (chat.TryGetCurrentUser(out User user))
{
Console.WriteLine($"Current user is {user.Name}");

// perform additional actions with the user if needed
}
else
{
Console.WriteLine("Current user not found.");
}
Last updated on