On this page

Manage user details

Retrieve user details from your app.

Get user details

getUser() returns data about a specific user, including all custom metadata by default.

Requires App Context

Enable App Context in the Admin Portal to store user data.

Method signature

This method takes the following parameters:

1chat.getUser(userId: String): PNFuture<User?>

Input

* required
ParameterDescription
userId *
Type: String
Default:
n/a
Unique user identifier (up to 92 UTF-8 characters).

Output

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

Sample code

Get details on user support_agent_15.

1// reference the "chat" object and invoke the "getUser()" method
2chat.getUser("support_agent_15").async { result ->
3result.onSuccess {
4 // handle success
5 }.onFailure {
6 // handle failure
7 }
8}

Get current user

currentUser returns the current chat user.

Requires App Context

Enable App Context in the Admin Portal to store user data.

Sample code

Return the current chat user.

1try {
2 Result.success(chat.currentUser)
3}.onSuccess { user ->
4 user?.let {
5 println("Current user is ${it.name} with ID ${it.id}")
6 } ?: run {
7 println("No current user in chat")
8 }
9}.onFailure { exception ->
10 println("Failed to retrieve current user: ${exception.message}")
11}
Last updated on