# Create Channel

`ChannelRepository` offers a function to create a new channel. This function provides support for creating three distinct types of channels, including `Community`, `Live`, and `Conversation`. Each channel type has its own unique characteristics and capabilities as we explained earlier, and the create channel function allows users to easily create and customize channels to suit their specific needs.

The SDK offers two standard ways for creating channels. The first method involves specifying a specific channel ID during the channel creation process. The second method allows for the automatic generation of a unique channel ID. The create channel API is designed to ensure that the channel being created is new, and if the requested channel already exists, it will return a conflict error (400900). The channel ID parameter in the channel creation function may be left undefined, in which case the SDK will automatically generate a unique channel ID to avoid any conflicts with existing IDs.

### Create Community Channel

This function on the SDK allows you to create a new [#community-channel](https://docs.social.plus/social-plus-sdk/chat/channels/..#community-channel "mention"). The `displayName` parameter is a required field, and it represents the public display name of the channel.

Here is a brief explanation of the function parameters:

* `displayName`: The public display name of the channel.
* `avatarFileId`: The image fileId that represents the image of the channel.
* `metaData`: Additional properties to support custom fields.
* `tags` - Arbitrary strings that can be used for defining and querying for the channels.
* `isPublic` - Specify visibility for the community channel that public or private community.

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/34db9df40e2ebd19445d541ee5dfe805#file-create_a_channel-swift>" %}
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/amythee/25ffa4ad070a4872a5c7d346e162991d>" %}
{% endtab %}

{% tab title="JavaScript" %}
Supported ✅ (please wait while we prepare a real example!)
{% endtab %}

{% tab title="TypeScript" %}
Version 6

{% embed url="<https://gist.github.com/0b04f93db28848f8381c21d3b90fcc47>" %}

Beta (v0.0.1)

{% embed url="<https://gist.github.com/387a061f5af33b02270813008206fa90>" %}
{% endtab %}

{% tab title="Flutter" %}
{% embed url="<https://gist.github.com/amythee/419b175b2bc54175b29d42c36c346409#file-amitychannelcreationcommunity-dart>" %}
{% endtab %}
{% endtabs %}

### Create Live Channel

Similar to the community channel creation function, the function allows you to create a new [#live-channel](https://docs.social.plus/social-plus-sdk/chat/channels/..#live-channel "mention"). The `displayName` parameter is a required field, and it represents the public display name of the channel.

Here is a brief explanation of the function parameters:

* `displayName`: The public display name of the channel.
* `avatarFileId`: The image fileId that represents the image of the channel.
* `metaData`: Additional properties to support custom fields.
* `tags` - Arbitrary strings that can be used for defining and querying for the channels.

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/b38c14ebe179f6e4ddc6840f29eeebcd>" %}
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/amythee/5bb0734843d552d28e036e2c33f4c09e>" %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { ChannelRepository, ChannelType } from '@amityco/js-sdk';

const liveChannel = ChannelRepository.createChannel({
  channelId: 'channel1',
  type: ChannelType.Community,
  userIds: [ 'user1', 'user2' ],
})

liveChannel.once('dataUpdated', model => {
  console.log(`Channel created: ${model.channelId}`);
});

liveChannel.once('dataError', error => {
  // Handle channel create error (non-unique channelID)
});
```

{% endtab %}

{% tab title="TypeScript" %}
Version 6

{% embed url="<https://gist.github.com/19fede77901e8f82f8326470559004a1>" %}

Beta (v0.0.1)

{% embed url="<https://gist.github.com/10c6186ecc65be2d9ec5438c8cd2d3b2>" %}
{% endtab %}

{% tab title="Flutter" %}
{% embed url="<https://gist.github.com/amythee/271c958e1f5ff915883086d38bd9740c#file-amitychannelcreationlive-dart>" %}
{% endtab %}
{% endtabs %}

### Create Conversation Channel

The [#conversation](https://docs.social.plus/social-plus-sdk/chat/channels/..#conversation "mention") channel creation function can also be utilized to create channels of the Conversation type. However, it should be noted that the channel ID for these channels will always be generated by the SDK. This ensures that the channel ID is unique and avoids any potential conflicts with existing channels

Here is a brief explanation of the function parameters:

* `userId`: The userId of the user that you'd like to chat with.
* `displayName`: The public display name of the channel.
* `avatarFileId`: The image fileId that represents the image of the channel.
* `metaData`: Additional properties to support custom fields.
* `tags` - Arbitrary strings that can be used for defining and querying for the channels.

{% hint style="info" %}
The conversation channel is unique based on its membership. When creating a conversation, the system will check if a channel with the same membership already exists. If such a channel already exists, the system will return the existing channel instead of creating a new one.
{% endhint %}

{% tabs %}
{% tab title="iOS" %}
{% embed url="<https://gist.github.com/amythee/c55852c8cc5c96b3bd5a8d81e20fd265>" %}
{% endtab %}

{% tab title="Android" %}
{% embed url="<https://gist.github.com/amythee/ff89fc4222a0e00f98db7d8ad425d613>" %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { ChannelRepository, ChannelType } from "@amityco/js-sdk"

const liveChannel = ChannelRepository.createChannel({ type: ChannelType.Conversation })

liveChannel.once('dataUpdated', () => {
  console.log('channel created');
});

```

{% endtab %}

{% tab title="TypeScript" %}
Version 6

{% embed url="<https://gist.github.com/6bec8d55b28323ba6cf6035b7fa99507>" %}

Beta (v0.0.1)

{% embed url="<https://gist.github.com/248d1fd731014dc706be6ba09ade5eae>" %}
{% endtab %}

{% tab title="Flutter" %}
{% embed url="<https://gist.github.com/amythee/35ae79e4b9f153098ef58a469e0b012b#file-amitychannelcreationconversation-dart>" %}
{% endtab %}
{% endtabs %}

### Create Broadcast Channel

[#broadcast](https://docs.social.plus/social-plus-sdk/chat/channels/..#broadcast "mention") channel can only be created from the social.plus Console. We recommend to see instructions in [#create-channel](https://docs.social.plus/analytics-and-moderation/console/chat-management/channel-management#create-channel "mention") on how to create a Broadcast channel.
