---
source_url: https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/create
title: Create channels
updated_at: 2026-06-04T11:08:59.085Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Create channels

:::tip Channel naming
Before creating channels, take the time to carefully plan your [naming strategy](https://www.pubnub.com/docs/general/channels/channel-naming). Stick to consistent naming conventions and structure your channels thoughtfully. This preparation helps you avoid increased complexity, performance bottlenecks, and scalability issues, ensuring your app remains manageable and efficient as it grows.
:::

Create channels ([Channel](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/channel) objects) of one of these types:

* [Direct (1:1)](#create-direct-channel)
* [Group](#create-group-channel)
* [Public](#create-public-channel)

:::note Requires App Context
To store data about channels, you must [enable App Context](https://youtu.be/9UEoSlngpYI) for your app's keyset in the [Admin Portal](https://admin.pubnub.com/).
:::

:::warning No support for channel groups
Chat SDKs don't support channel groups. We recommend using a [Core SDK](https://www.pubnub.com/docs/sdks) to manage [channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups).
:::

## Create direct channel

Direct channels enable private 1:1 conversations. Use cases include personal conversations and professional collaboration.

`createDirectConversation()` performs these actions:

1. Creates a channel with the `direct` type
2. Sets [channel membership](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/membership) for the channel owner
3. [Invites](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/invite#invite-one-user) the other user (generates an [invite event](https://www.pubnub.com/docs/chat/chat-sdk/build/features/custom-events#events-for-channel-initations))

If a conversation between the two users already exists, the method returns that existing channel.

:::note Receive messages
Call [onMessageReceived()](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/watch) to start receiving messages on the channel.
:::

### Method signature

##### Under the hood

`createDirectConversation()` calls App Context API and the JavaScript SDK [setChannelMetadata()](https://www.pubnub.com/docs/sdks/javascript/api-reference/objects#set-channel-metadata) and [setMemberships()](https://www.pubnub.com/docs/sdks/javascript/api-reference/objects#set-channel-memberships) methods.

This method takes the following parameters:

```ts
chat.createDirectConversation({ user, channelData, membershipData, }: {
    user: User,
    channelId?: string
    channelData?: {
        name?: string,
        description?: string,
        custom?: ObjectCustom
    },
    membershipData?: {
        custom: ObjectCustom
    }
}): Promise<{
    channel: Channel,
    hostMembership: Membership,
    inviteeMembership: Membership,
}>
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| user | User | Yes |  | User that you invite to join a channel. |
| channelId | string | Optional | `Automatically generated ID` | ID of the direct channel. The channel ID is created automatically by a hashing function that takes the string of two user names joined by `&`, computes a numeric value based on the characters in that string, and adds the `direct` prefix in front. For example, `direct.1234567890`. You can override this default value by providing your own ID. |
| channelData | object | Optional |  | Information about the channel. |
| > name | string | Optional |  | Display name for the channel. If you don't provide the name, the channel will get the same name as [id](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/channel) (value of `channelId`). |
| > description | string | Optional |  | Additional details about the channel. |
| > custom | any | Optional |  | Any custom properties or metadata associated with the channel. |
| membershipData | object | Optional |  | Information about the user-channel [membership](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/membership). |
| > custom | ObjectCustom | Yes |  | Any custom properties or metadata associated with the channel membership in the form of a JSON. Values must be scalar only; arrays or objects are not supported. [App Context filtering language](https://www.pubnub.com/docs/general/metadata/filtering) doesn’t support filtering by custom properties. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Output

| Parameter | Description |
| --- | --- |
| `Promise<>`Type: `object` | Returned object containing these fields: `channel`, `hostMembership`, and `inviteeMembership`. |
| `> channel`Type: [Channel](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/channel) | Returned object containing the updated channel metadata. |
| `> hostMembership`Type: [Membership](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/membership) | Returned object containing the updated host (channel owner) metadata. |
| `> inviteeMembership`Type: `Membership` | Returned object containing the updated data of the invited user. |

### Sample code

Invite `agent-007` to a 1:1 conversation to talk about `customer XYZ`.

```ts
// reference the person you want to talk to
const userToChatWith = await chat.getUser("agent-007")

// add the channel name and topic
const { channel, hostMembership, inviteeMembership } = await chat.createDirectConversation(
    {
        user: userToChatWith,
        channelData: {
            name: "Quick sync on customer XYZ"
        },
        membershipData: {
            custom: {
                purpose: "premium-support"
            }
        }
    }
)
```

## Create group channel

Group channels enable multi-user conversations for team collaboration and community building. Access requires an invitation.

`createGroupConversation()` performs these actions:

1. Creates a channel with the `group` type
2. Sets channel membership for the channel owner
3. [Invites](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/invite#invite-multiple-users) other users to join

:::note Receive messages
Call [onMessageReceived()](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/watch) to start receiving messages on the channel.
:::

### Method signature

##### Under the hood

`createGroupConversation()` calls App Context API and the JavaScript SDK [setChannelMetadata()](https://www.pubnub.com/docs/sdks/javascript/api-reference/objects#set-channel-metadata) and [setMemberships()](https://www.pubnub.com/docs/sdks/javascript/api-reference/objects#set-channel-memberships) methods.

This method takes the following parameters:

```ts
chat.createGroupConversation({ users, channelId, channelData, membershipData, }: {
    users: User[],
    channelId?: string
    channelData?: {
        name?: string,
        description?: string,
        custom?: ObjectCustom
    },
    membershipData?: {
        custom: ObjectCustom
    }
}): Promise<{
    channel: Channel,
    hostMembership: Membership,
    inviteesMemberships: Membership[],
}>
```

#### Input

| Parameter | Description |
| --- | --- |
| `users` *Type: `User[]`Default: n/a | List of users that you invite to join a channel. You can invite a maximum number of 100 users at once as this is the limitation set by the [App Context API](https://www.pubnub.com/docs/sdks/javascript/api-reference/objects#set-channel-memberships) that the `inviteMultiple()` method calls. |
| `channelId`Type: `string`Default: Automatically generated UUIDv4 | ID of the group channel. The channel ID is created automatically using the [UUIDv4 module](https://www.npmjs.com/package/uuidv4). You can override it by providing your own ID. |
| `channelData`Type: `object`Default: n/a | Information about the channel. |
| `> name`Type: `string`Default: n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as [id](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/channel) (value of `channelId`). |
| `> description`Type: `string`Default: n/a | Additional details about the channel. |
| `> custom`Type: `any`Default: n/a | Any custom properties or metadata associated with the channel. |
| `membershipData`Type: `object`Default: n/a | Information about the user-channel memberships. |
| `> custom` *Type: `ObjectCustom`Default: n/a | Any custom properties or metadata associated with the channel membership in the form of a JSON. Values must be scalar only; arrays or objects are not supported. [App Context filtering language](https://www.pubnub.com/docs/general/metadata/filtering) doesn’t support filtering by custom properties. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Output

| Parameter | Description |
| --- | --- |
| `Promise<>`Type: `object` | Returned object containing these fields: `channel`, `hostMembership`, and `inviteeMembership`. |
| `> channel`Type: `Channel` | Returned object containing the updated channel metadata. |
| `> hostMembership`Type: `Membership` | Returned object containing the updated host (channel owner) data. |
| `> inviteesMemberships`Type: `Membership[]` | Returned object containing the updated metadata of the invited users. |

### Sample code

Create a group conversation and invite `agent-007` and `agent-008` to have weekly syncs on `customer XYZ`.

```ts
// reference both agents you want to talk to
const user1 = await chat.getUser("agent-007")
const user2 = await chat.getUser("agent-008")

// add the channel ID, name, and topic
const { channel, hostMembership, inviteesMemberships } = await chat.createGroupConversation(
    {
        users: 
        [
            user1,
            user2
        ],
        channelId: "group-chat-1"
        channelData: {
            name: "Weekly syncs on customer XYZ"
        },
        membershipData: {
            custom: {
                purpose: "premium-support"
            }
        }
    }
)
```

## Create public channel

Public channels are open to anyone without invitation. Use cases include Q&A forums, knowledge sharing, and live event chat.

:::warning Supported features
Public channels do not support [typing indicators](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/typing-indicator) or [read receipts](https://www.pubnub.com/docs/chat/chat-sdk/build/features/messages/read-receipts). These features are impractical for large audiences.
:::

`createPublicConversation()` creates a channel with the `public` type and the specified metadata.

:::note Receive messages
Call [onMessageReceived()](https://www.pubnub.com/docs/chat/chat-sdk/build/features/channels/watch) to start receiving messages on the channel.
:::

### Method signature

##### Under the hood

`createPublicConversation()` calls App Context API and the JavaScript SDK [setChannelMetadata()](https://www.pubnub.com/docs/sdks/javascript/api-reference/objects#set-channel-metadata) method.

This method takes the following parameters:

```ts
chat.createPublicConversation({ channelId, channelData, }: {
    channelId?: string
    channelData?: {
        name?: string,
        description?: string,
        custom?: ObjectCustom
    }
}): Promise<Channel>
```

#### Input

| Parameter | Description |
| --- | --- |
| `channelId`Type: `string`Default: Automatically generated UUIDv4 | ID of the public channel. The channel ID is created automatically using the [UUIDv4 module](https://www.npmjs.com/package/uuidv4). You can override it by providing your own ID. |
| `channelData`Type: `object`Default: n/a | Information about the channel. |
| `> name`Type: `string`Default: n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as [id](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/channel) (value of `channelId`). |
| `> description`Type: `string`Default: n/a | Additional details about the channel. |
| `> custom`Type: `any`Default: n/a | Any custom properties or metadata associated with the channel. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Output

| Type | Description |
| --- | --- |
| `Promise<Channel>` | Object returning the created channel metadata. |

### Sample code

Create a public `ask-support` channel.

```ts
const = await chat.createPublicConversation(
    {
        channelId: "support-channel-4"
        channelData: {
            name: "ask-support"
            description: "Space dedicated to answering all support-related questions"
        }
    }
)
```