Manage user details
Get details about the app users.
Get user details
Return data about a specific user with the TryGetUser()
or GetUserAsync
methods.
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
- Sync
- Async
chat.TryGetUser(
string userId,
out User user
)
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
id | string | Yes | n/a | Unique user identifier (up to 92 UTF-8 characters). |
user | out User | Yes | n/a | The 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}");
};
chat.GetUserAsync(
string userId
)
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
id | string | Yes | n/a | Unique user identifier (up to 92 UTF-8 characters). |
Output
The method returns an awaitable Task<User?>
with the found User
object or null
if there wasn't one.
Basic usage
Get details on user support_agent_15
.
var user = await chat.GetUserAsync("support_agent_15");
if (user != null)
{
Console.WriteLine($"Found user with name {user.Name}");
};
Get current user
TryGetCurrentUser
and GetCurrentUserAsync()
are methods that return 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
- Sync
- Async
chat.TryGetCurrentUser(out User user)
Input
This method doesn't take any parameters.
Output
Parameter | Type | Description |
---|---|---|
user | out User | The 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.");
}
chat.GetCurrentUserAsync()
Input
This method has no parameters.
Output
The method returns an awaitable Task<User?>
with the found User
object or null
if there wasn't one.
Basic usage
Asynchronously return the current chat user.
var currentUser = await chat.GetCurrentUserAsync();
if (currentUser != null)
{
Console.WriteLine($"Current user is {currentUser.Name}");
// perform additional actions with the user if needed
}
else
{
Console.WriteLine("Current user not found.");
}