Delete channels

Chat SDK lets you remove an existing channel (with or without deleting its historical data from the App Context storage) using one of these methods: delete() and deleteChannel().

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

Requires App Context

To store data about channels, 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()

    channel.delete({
    soft?: boolean
    }): Promise<true | Channel>
  • deleteChannel()

    chat.deleteChannel(
    id: string,
    {
    soft?: boolean
    }
    ): Promise<true | Channel>

Input

ParameterTypeRequired in delete()Required in deleteChannel()DefaultDescription
idstringNoYesn/aUnique channel identifier.
softbooleanNoNofalseDefine if you want to permanently remove channel metadata. The channel metadata gets permanently deleted from the App Context storage by default. If you set this parameter to true, the Channel object gets the deleted status, and you can still restore/get its data.

Output

TypeDescription
Promise<true> or Promise<Channel>For hard delete, a confirmation that the channel metadata was permanently deleted. For soft delete, an updated channel instance with the status field set to deleted.

Errors

Whenever the channel ID is required, and you try to delete a channel without providing its ID, you will receive the ID is required error.

Basic usage

Permanently delete the support channel metadata.

  • delete()

    // reference the "channel" object
    const channel = await chat.getChannel("support")
    // invoke the "delete()" method. By default, the "soft" parameter is set to "false" and can be skipped.
    await channel.delete()
  • deleteChannel()

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

Other examples

Archive (soft delete) the channel with the ID of support, keeping its data in the App Context storage.

  • delete()

    const channel = await chat.getChannel("support")
    await channel.delete(
    {
    soft: true
    }
    )
  • deleteChannel()

    await chat.deleteChannel(
    "support",
    {
    soft: true
    }
    )
Last updated on