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({
2 soft?: boolean
3}): Promise<true | User> -
deleteUser()1chat.deleteUser(
2 id: string,
3 {
4 soft?: boolean
5 }
6): Promise<true | 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 |
|---|---|
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.
Sample code
Permanently delete user support_agent_15.
-
delete()1// reference the "user" object
2const user = await chat.getUser("support_agent_15")
3// invoke the "delete()" method. By default, the "soft" parameter is set to "false" and can be skipped.
4await user.delete() -
deleteUser()1// reference the "chat" object and invoke the "deleteUser()" method. By default, the "soft" parameter is set to "false" and can be skipped.
2const user = await chat.deleteUser(
3 "support_agent_15"
4)
Other examples
Archive (soft delete) the user with an ID of support_agent_15, keeping their data in the App Context storage.
-
delete()1const user = await chat.getUser("support_agent_15")
2await user.delete(
3 {
4 soft: true
5 }
6) -
deleteUser()1await chat.deleteUser(
2 "support_agent_15",
3 {
4 soft: true
5 }
6)