Manage user details

Get details about the app users.

Get user details

Return data about a specific user with the getUser() 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.getUser(userId: String): PNFuture<User?>

Input

ParameterTypeRequiredDefaultDescription
userIdStringYesn/aUnique user identifier (up to 92 UTF-8 characters).

Output

TypeDescription
PNFuture<User?>PNFuture containing the user object with its metadata.

Basic usage

Get details on user support_agent_15.

// reference the "chat" object and invoke the "getUser()" method
chat.getUser("support_agent_15").async { result ->
result.onSuccess {
// handle success
}.onFailure {
// handle failure
}
}

Get current user

You can access the currentUser property of the Chat object to get 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.

Basic usage

Return the current chat user.

try {
Result.success(chat.currentUser)
}.onSuccess { user ->
user?.let {
println("Current user is ${it.name} with ID ${it.id}")
} ?: run {
println("No current user in chat")
}
}.onFailure { exception ->
println("Failed to retrieve current user: ${exception.message}")
}
Last updated on