Create a channel
Two basic types of channels you can create with Sendbird Chat SDK are open channels and group channels.
An open channel is ideal for use cases that don't require a permanent membership in the channel, such as short-lived live events and news-feed style messaging to a large audience. On the other hand, a group channel is suitable for closer interactions among a limited number of users. To learn more about the different use cases and characteristics of open and group channels, see the channel overview page.
When creating a channel, you can append additional information like cover image, description, and URL by passing several arguments to the corresponding parameters. The channel URL can only contain numbers, letters, underscores, or hyphens, and the URL's length must be between 4 and 100 characters. If you don't specify the channelUrl
property, a URL is automatically generated.
If you want to create and continue to use a single group channel for a 1-to-1 chat, set the isDistinct
property of the channel to true
. If the isDistinct
property is set to false
, multiple 1-to-1 channels with their own chat history and data may be created for the same two users even if a channel already exists between them.
Note: By default, the Allow creating open channels and Allow creating group channels options are turned on, which means that any user can create open and group channels with Sendbird Chat SDK. This may grant access to unwanted data or operations, leading to potential security concerns. To manage your access control settings, you can turn on or off each option in Settings > Application > Security > Access control list on Sendbird Dashboard.
Open channel
An open channel is ideal for use cases that require a small and static number of channels. To create an open channel from Sendbird Dashboard, do the following.
- On Sendbird Dashboard, go to Chat > Open channels, and then click Create channel at the top-right corner.
- In the dialog box that appears, specify the name, unique URL, cover image, and custom type of a channel.
Alternatively, you can create a channel on demand or dynamically through the Chat SDK or the Chat Platform API. Use the following code to create a channel through the Chat SDK.
Or you can create an open channel by configuring an OpenChannelCreateParams
object like the following.
OpenChannelCreateParams
Property name | Type | Description |
---|---|---|
name | String | Specifies the channel topic, or the name of the channel. |
channelUrl | String | Specifies a unique channel URL given when a new open channel is created. |
data | String | Specifies additional channel information such as a long description of the channel or |
operatorUserIds | List<String> | Specifies an array of one or more users to register as operators of the channel. Operators can delete any messages, and also view all messages in the channel without any filtering or throttling. |
customType | String | Specifies the custom channel type which is used for channel grouping. |
Note: See categorize channels by custom type for more information on cover images and custom types.
Group channel
A user can create a group channel by inviting other users in their client app. At the implementation level, you need to create a GroupChannelCreateParams
object with a list of user IDs to invite. In the params, you can also specify a user ID to designate an operator in the channel. Then, run code that passes the user ID list as an argument to a parameter in the createChannel()
method.
Before running the code that creates a group channel for a typical 1-to-1 chat, you should make sure that you set the value of the isDistinct
property to true
. If the value of the isDistinct
property is set to false
, a new channel is created with the same two users even if there is already an existing channel between them. In this case, multiple 1-to-1 channels between the same two users can exist, each with its own chat history and data.
However, if you plan to create a Supergroup channel, the value of the isDistinct
property should be set to false
.
GroupChannelCreateParams
Property name | Type | Description |
---|---|---|
userIds | List<String> | A list of user IDs to include as channel members. |
operatorUserIds | List<String> | A list of user IDs to include as channel operators. |
Supergroup channel
Creating a Supergroup channel follows the exact same process of creating a group channel with the exception of the isSuper
property. The GroupChannelCreateParams
class has the isSuper
property that determines whether a newly created channel is a Supergroup channel or a regular group channel. Set the value of this property to true
to create a new Supergroup channel.
Because the distinct option isn't available for Supergroup channels, the isDistinct
property is set to false
by default when creating a Supergroup channel.