Skip to content

Deleting Channels

You can delete or truncate a channel to remove its contents. To remove only messages while preserving the channel, see Truncate Channel.

Deleting a Channel

You can delete a single Channel using the  delete  method. This marks the channel as deleted and hides all the messages.

val channelClient = client.channel("messaging", "general")

channelClient.delete().enqueue { result ->
  if (result is Result.Success) {
    val channel = result.value
  } else {
    // Handle Result.Failure
  }
}
Info:

If you recreate this channel, it will show up empty. Recovering old messages is not supported, unless the channel was deleted with skip_truncate (see Preserving message history below). Use the disable method if you want a fully reversible change.

Preserving Message History

By default, deleting a channel hides its messages, so a channel later recreated with the same ID starts out empty. Set skip_truncate to true to preserve message history through the delete instead, so a channel later recreated with the same ID (for example with GetOrCreateChannel) restores the full message history.

This is useful for apps where the same pair of users can end up back in the same channel, for example a dating app where two users unmatch and later re-match.

Warning:

skip_truncate is server-side only and only supported on distinct channels. It cannot be combined with hard_delete, and it cannot be used if the channel's messages were already hidden by an earlier delete or truncate.

Java
// Backend SDK - preserve history through the soft delete
chat.deleteChannel(channel.getType(), channel.getId(),
    DeleteChannelRequest.builder().SkipTruncate(true).build()).execute();

Deleting Many Channels

You can delete up to 100 channels and optionally all of their messages using this method. This can be a large amount of data to delete, so this endpoint processes asynchronously, meaning responses contain a task ID which can be polled using the getTask endpoint to check status of the deletions. Channels will be soft-deleted immediately so that channels no longer return from queries, but permanently deleting the channel and deleting messages takes longer to process.

By default, messages are soft deleted, which means they are removed from client but are still available via server-side export functions. You can also hard delete messages, which deletes them from everywhere, by setting "hard_delete": true in the request. Messages that have been soft or hard deleted cannot be recovered.

You can also set skip_truncate to true to preserve message history for every channel in the request, the same as for a single channel delete. If any of the given CIDs is not eligible (it isn't a distinct channel, or its messages were already hidden by an earlier delete or truncate), the entire request is rejected and none of the channels are deleted.

This is currently supported on the following SDK versions (or higher):

  • Javascript 4.3.0, Python 3.14.0, Ruby 2.12.0, PHP 2.6.0, Go 3.13.0, Java 1.4.0, Unity 2.0.0 and .NET 0.22.0
Java
// soft deletion
var response = chat.deleteChannels(DeleteChannelsRequest.builder()
    .cids(List.of(cid1, cid2))
    .build()).execute();

// hard deletion
response = chat.deleteChannels(DeleteChannelsRequest.builder()
    .cids(List.of(cid1, cid2))
    .hardDelete(true)
    .build()).execute();

var taskResponse = client.getTask(response.getData().getTaskId()).execute();
// "completed".equals(taskResponse.getData().getStatus());

// preserve history (distinct channels only)
response = chat.deleteChannels(DeleteChannelsRequest.builder()
    .cids(List.of(cid1, cid2))
    .skipTruncate(true)
    .build()).execute();

The  deleteChannels  response contain a taskID which can be polled using the getTask endpoint to check the status of the deletions.