Delete users

Two methods let you remove an existing user: delete() and deleteUser(). You can remove the user either with or without deleting their historical data from the App Context storage.

Both of these methods give the same output. The only difference is that you call a given method either on the Chat (deleteUser()) or the User (delete()) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the user ID you want to delete or not because it's already known.

Requires App Context

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

Method signature

These methods take the following parameters:

  • delete()

    user.delete(soft: Boolean = false): PNFuture<User>
  • deleteUser()

    chat.deleteUser(id: String, soft: Boolean = false): PNFuture<User>

Input

ParameterTypeRequired in delete()Required in deleteUser()DefaultDescription
idStringNoYesn/aUnique user identifier (up to 92 UTF-8 characters).
softBooleanNoNofalseDefine 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

TypeDescription
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.

Basic usage

Permanently delete user support_agent_15.

  • delete()

    // reference the "chat" object and invoke the "getUser()" method
    chat.getUser("support_agent_15").async { result ->
    result.onSuccess { user ->
    // attempt to permanently delete the user
    val deleteUserFuture = user.delete()

    deleteUserFuture.async { deleteResult ->
    deleteResult.onSuccess { deletedUser ->
    // handle success
    println("User ${deletedUser.id} successfully deleted permanently.")
    }.onFailure { exception ->
    // handle failure
    exception.printStackTrace()
    println("Failed to delete the user: ${exception.message}")
    }
    show all 22 lines
  • deleteUser()

    // reference the "chat" object and directly invoke the "deleteUser()" method
    chat.deleteUser("support_agent_15").async { deleteResult ->
    deleteResult.onSuccess { deletedUser ->
    // handle success
    println("User ${deletedUser.id} successfully deleted permanently.")
    }.onFailure { exception ->
    // handle failure
    exception.printStackTrace()
    println("Failed to delete the user: ${exception.message}")
    }
    }

Other examples

Archive (soft delete) the user with an ID of support_agent_15, keeping their data in the App Context storage.

  • delete()

    // reference the "chat" object and invoke the "getUser()" method
    chat.getUser("support_agent_15").async { result ->
    result.onSuccess { user ->
    // attempt to soft delete (archive) the user
    val deleteUserFuture = user.delete(soft = true)

    deleteUserFuture.async { deleteResult ->
    deleteResult.onSuccess { archivedUser ->
    // handle success
    println("User ${archivedUser.id} successfully archived (soft deleted).")
    }.onFailure { exception ->
    // handle failure
    exception.printStackTrace()
    println("Failed to archive the user: ${exception.message}")
    }
    show all 22 lines
  • deleteUser()

    // Reference the "chat" object and directly invoke the "deleteUser()" method
    chat.deleteUser("support_agent_15", soft = true).async { deleteResult ->
    deleteResult.onSuccess { archivedUser ->
    // handle success
    println("User ${archivedUser.id} successfully archived (soft deleted).")
    }.onFailure { exception ->
    // handle failure
    exception.printStackTrace()
    println("Failed to archive the user: ${exception.message}")
    }
    }
Last updated on