Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Channel
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

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 such as short-lived live events and news-feed style messaging to a massive audience that doesn't require a permanent membership in the channel. 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 page on channel types.

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 a group channel for a 1-to-1 chat, you should make sure that you set the isDistinct property of the channel to true. Otherwise, if the isDistinct property is set to false, multiple 1-to-1 channels, each with their own chat history and data, may be created for the same two users even if a channel already exists between them.


Open channel

You can create an open channel by passing a configured OpenChannelCreateParams object as an argument to the parameter in the createChannel() method like the following.

const params: OpenChannelCreateParams = {
    name: NAME,
    channelUrl: UNIQUE_CHANNEL_URL,
    coverUrlOrImage: FILE | COVER_URL,
    operatorUserIds: ['Hoon', 'Doo'],
    data: DATA,
    customType: CUSTOM_TYPE,
    // ...
};
const channel: OpenChannel = await sb.openChannel.createChannel(params);

OpenChannelCreateParams

Property nameTypeDescription

name

string

Specifies the name of the channel.

coverUrlOrImage

string or File

Specifies the cover image URL of the channel, or uploads a file for the cover image.

channelUrl

string

Specifies the URL of the channel. Only numbers, letters, underscores, and hyphens are allowed. The length must be between 4 and 100 characters. If the channelUrl property isn't specified, a URL is automatically generated.

operatorUserIds

string[]

Specifies an array of one or more IDs of the users to register as operators of the channel. Operators can delete any messages and view all messages in the channel without any filtering or throttling.

data

string

Specifies additional channel information such as a long description of the channel or a JSON formatted string.

customType

string

Specifies the custom channel type which is used for channel grouping.


Group channel

You can create a group channel by passing a configured GroupChannelCreateParams object as an argument to the parameter in the createChannel() method like the following.

const params: GroupChannelCreateParams = {
    invitedUserIds: ['John', 'Harry'],
    name: NAME,
    channelUrl: UNIQUE_CHANNEL_URL,
    coverUrl: COVER_URL, // Or .coverImage to upload a cover image file
    operatorUserIds: ['Hoon', 'Doo'],
    data: DATA,
    customType: CUSTOM_TYPE,
    isDistinct: IS_DISTINCT,
    // ...
};
const channel: GroupChannel = await sb.groupChannel.createChannel(params);

GroupChannelCreateParams

Property nameTypeDescription

name

string

Specifies the channel topic or the name of the channel.

coverUrl

string

Specifies the cover image URL of the channel. Alternatively, you can upload a file for the cover image of the channel using the coverImage property.

invitedUserIds

string[]

Specifies an array of one or more IDs of the users invited to the group channel.

operatorUserIds

string[]

Specifies an array of one or more IDs of the users to register as operators of the channel. Operators can delete any messages and view all messages in the channel without any filtering or throttling.

isDistinct

boolean

Determines whether to reuse an existing channel or create a new channel. Setting this property to true returns a channel with the same users in USER_IDS or creates a new channel if no match is found. If set to false, the Sendbird server always creates a new channel with the specified combination of users as well as the channel custom type.

* You can also use this property in conjunction with CUSTOM_TYPE and USER_IDS to create distinct channels for a specified channel custom type and a set of specified users. In order to enable the functionality, visit this page and contact us on Sendbird Dashboard.

customType

string

Specifies the custom channel type which is used for channel grouping.

Using the getCoverUrl() and updateChannel() methods, you can get and update the cover image URL of a channel.

Note: You can also use the Chat API to create open channels and group channels. For group channels, using the Chat API helps you control channel member invitations on your server side.


Supergroup channel

Creating a Supergroup channel follows the same process as creating a group channel with one exception of the isSuper property. The GroupChannelCreateParams object includes the isSuper property, which determines whether a newly created channel is a Supergroup channel or a regular group channel. Setting isSuper to true creates 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.

const params: GroupChannelCreateParams = {
    isSuper: true,
};
const channel: GroupChannel = await sb.groupChannel.createChannel(params);