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

icon

Under the hood


These methods take the following parameters:

  • delete()

    user.delete({
    soft?: boolean
    }): Promise<true | User>
  • deleteUser()

    chat.deleteUser(
    id: string,
    {
    soft?: boolean
    }
    ): Promise<true | 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
Promise<true> or Promise<User>For hard delete, a confirmation that the user metadata was permanently deleted. For soft delete, an updated user instance with the status field set to deleted.

Errors

Whenever the user ID is obligatory, and you try to delete a user without providing their ID, you will receive the ID is required error.

Basic usage

Permanently delete user support_agent_15.

  • delete()

    // reference the "user" object
    const user = await chat.getUser("support_agent_15")
    // invoke the "delete()" method. By default, the "soft" parameter is set to "false" and can be skipped.
    await user.delete()
  • deleteUser()

    // reference the "chat" object and invoke the "deleteUser()" method. By default, the "soft" parameter is set to "false" and can be skipped.
    const user = await chat.deleteUser(
    "support_agent_15"
    )

Other examples

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

  • delete()

    const user = await chat.getUser("support_agent_15")
    await user.delete(
    {
    soft: true
    }
    )
  • deleteUser()

    await chat.deleteUser(
    "support_agent_15",
    {
    soft: true
    }
    )
Last updated on