Delete users
Remove users with delete() or deleteUser(). Choose between permanent deletion or soft delete (preserving data in App Context storage).
delete()- call on aUserobject (no ID needed)deleteUser()- call on aChatobject (requires user ID)
Requires App Context
Enable App Context in the Admin Portal to store user data.
Method signature
These methods take the following parameters:
-
delete()1user.delete(soft: Boolean = false): PNFuture<User> -
deleteUser()1chat.deleteUser(id: String, soft: Boolean = false): PNFuture<User>
Input
| Parameter | Required in delete() | Required in deleteUser() | Description |
|---|---|---|---|
idType: StringDefault: n/a | No | Yes | Unique user identifier (up to 92 UTF-8 characters). |
softType: BooleanDefault: false | No | No | Define if you want to permanently remove user metadata. The user metadata gets permanently deleted from the App Context storage by default. If you set this parameter to true, the User object gets the deleted status, and you can still restore/get their metadata. |
Output
| Type | Description |
|---|---|
PNFuture<User> | For hard delete, the method returns the last version of the User object before it was permanently deleted. For soft delete, an updated user instance with the status field set to deleted. |
Sample code
Permanently delete user support_agent_15.
-
delete()
show all 22 lines1// reference the "chat" object and invoke the "getUser()" method
2chat.getUser("support_agent_15").async { result ->
3 result.onSuccess { user ->
4 // attempt to permanently delete the user
5 val deleteUserFuture = user.delete()
6
7 deleteUserFuture.async { deleteResult ->
8 deleteResult.onSuccess { deletedUser ->
9 // handle success
10 println("User ${deletedUser.id} successfully deleted permanently.")
11 }.onFailure { exception ->
12 // handle failure
13 exception.printStackTrace()
14 println("Failed to delete the user: ${exception.message}")
15 } -
deleteUser()1// reference the "chat" object and directly invoke the "deleteUser()" method
2chat.deleteUser("support_agent_15").async { deleteResult ->
3 deleteResult.onSuccess { deletedUser ->
4 // handle success
5 println("User ${deletedUser.id} successfully deleted permanently.")
6 }.onFailure { exception ->
7 // handle failure
8 exception.printStackTrace()
9 println("Failed to delete the user: ${exception.message}")
10 }
11}
Other examples
Archive (soft delete) the user with an ID of support_agent_15, keeping their data in the App Context storage.
-
delete()
show all 22 lines1// reference the "chat" object and invoke the "getUser()" method
2chat.getUser("support_agent_15").async { result ->
3 result.onSuccess { user ->
4 // attempt to soft delete (archive) the user
5 val deleteUserFuture = user.delete(soft = true)
6
7 deleteUserFuture.async { deleteResult ->
8 deleteResult.onSuccess { archivedUser ->
9 // handle success
10 println("User ${archivedUser.id} successfully archived (soft deleted).")
11 }.onFailure { exception ->
12 // handle failure
13 exception.printStackTrace()
14 println("Failed to archive the user: ${exception.message}")
15 } -
deleteUser()1// Reference the "chat" object and directly invoke the "deleteUser()" method
2chat.deleteUser("support_agent_15", soft = true).async { deleteResult ->
3 deleteResult.onSuccess { archivedUser ->
4 // handle success
5 println("User ${archivedUser.id} successfully archived (soft deleted).")
6 }.onFailure { exception ->
7 // handle failure
8 exception.printStackTrace()
9 println("Failed to archive the user: ${exception.message}")
10 }
11}