Create channels

Create channels (Channel objects) of one of these types:

Requires App Context

To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.

Create direct channel

Direct channels enable private conversations between two users, letting one person initiate the chat and send an invitation to another person for:

  • Personal conversations - you can engage in private conversations with friends, family, or colleagues, sharing personal updates, discussing sensitive matters, or planning social events.

  • Professional collaboration - you can use 1:1 chat to have focused discussions, exchange confidential information, provide feedback, or coordinate tasks with colleagues and business partners.

createDirectConversation() is a method that:

  1. Creates a direct (one-on-one) channel type.
  2. Sets channel membership for the channel owner (so that they can join the channel).
  3. Invites the other user to join the channel. As a result, an event of the invite type gets created. You can listen to these events in your chat app and notify the invited users.

If you call this method to create a channel for users that already had a conversation which was not deleted, this conversation is retrieved.

Receive messages

Note that you still have to call the connect() method to subscribe to message event listeners and start receiving messages on the channel.

Method signature

icon

Under the hood


This method takes the following parameters:

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,
show all 16 lines

Input

ParameterTypeRequiredDefaultDescription
userUserYesn/aUser that you invite to join a channel.
channelIdstringNoAutomatically generated IDID 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.
channelDataobjectNon/aInformation about the channel.
 → namestringChannel IDn/aDisplay name for the channel.

If you don't provide the name, the channel will get the same name as id (value of channelId).
 → descriptionstringNon/aAdditional details about the channel.
 → customanyNon/aAny custom properties or metadata associated with the channel.
membershipDataobjectNon/aInformation about the user-channel membership.
 → customObjectCustomYesn/aAny 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 doesn’t support filtering by custom properties.
API limits

To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.

Output

ParameterTypeDescription
Promise<>objectReturned object containing these fields: channel, hostMembership, and inviteeMembership.
 → channelChannelReturned object containing the updated channel metadata.
 → hostMembershipMembershipReturned object containing the updated host (channel owner) metadata.
 → inviteeMembershipMembershipReturned object containing the updated data of the invited user.

Basic usage

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

// 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"
}
}
show all 17 lines

Create group channel

Group channels enable communication among multiple users, promoting collaboration and teamwork. A user can initiate a group chat and invite others to be channel members for:

  • Team collaboration - members of a project team can use group chat to share updates, exchange ideas, ask questions, and provide status updates. This boosts real-time collaboration and productivity and ensures everyone stays on the same page.

  • Community building - group chat allows like-minded individuals to connect, discuss shared interests, organize events, and build strong communities around specific topics, hobbies, or professional fields.

Such a chat type is restricted by invitation, and you can access it only when invited.

createGroupConversation() is a method that:

  1. Creates a group channel type.
  2. Sets channel membership for the channel owner (so that they can join the channel).
  3. Invites other users to join the channel.
Receive messages

Note that you still have to call the connect() method to subscribe to message event listeners and start receiving messages on the channel.

Method signature

icon

Under the hood


This method takes the following parameters:

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[],
show all 16 lines

Input

ParameterTypeRequiredDefaultDescription
usersUser[]Yesn/aList 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 that the inviteMultiple() method calls.
channelIdstringNoAutomatically generated UUIDv4ID of the group channel. The channel ID is created automatically using the UUIDv4 module. You can override it by providing your own ID.
channelDataobjectNon/aInformation about the channel.
 → namestringChannel IDn/aDisplay name for the channel.

If you don't provide the name, the channel will get the same name as id (value of channelId).
 → descriptionstringNon/aAdditional details about the channel.
 → customanyNon/aAny custom properties or metadata associated with the channel.
membershipDataobjectNon/aInformation about the user-channel memberships.
 → customObjectCustomYesn/aAny 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 doesn’t support filtering by custom properties.
API limits

To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.

Output

ParameterTypeDescription
Promise<>objectReturned object containing these fields: channel, hostMembership, and inviteeMembership.
 → channelChannelReturned object containing the updated channel metadata.
 → hostMembershipMembershipReturned object containing the updated host (channel owner) data.
 → inviteesMembershipsMembership[]Returned object containing the updated metadata of the invited users.

Basic usage

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

// 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, inviteeMembership } = await chat.createGroupConversation(
{
users:
[
user1,
user2
],
channelId: "group-chat-1"
channelData: {
name: "Weekly syncs on customer XYZ"
show all 23 lines

Create public channel

Supported features

The public channel type comes with certain limitations in place - you'll get errors when trying to implement such Chat SDK features as typing indicator, invites, or read receipts in public channels since these features are neither useful nor practical for large audiences.

Public channels let users engage in open conversations with many people. Unlike group chats, anyone can join public channels. Example use cases include:

  • Knowledge sharing and Q&A - public chats provide a platform for users to seek advice, share knowledge, and participate in discussions related to specific topics, fostering a community-driven environment.

  • Events and webinars - organizations can host public chats during live events, webinars, or panel discussions, allowing attendees to interact with presenters, ask questions, and share insights in real time.

createPublicConversation() is a method that creates such a public channel type with specified metadata.

Receive messages

Note that you still have to call the connect() method to subscribe to message event listeners and start receiving messages on the channel.

Method signature

icon

Under the hood


This method takes the following parameters:

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

Input

ParameterTypeRequiredDefaultDescription
channelIdstringNoAutomatically generated UUIDv4ID of the group channel. The channel ID is created automatically using the UUIDv4 module. You can override it by providing your own ID.
channelDataobjectNon/aInformation about the channel.
 → namestringChannel IDn/aDisplay name for the channel.

If you don't provide the name, the channel will get the same name as id (value of channelId).
 → descriptionstringNon/aAdditional details about the channel.
 → customanyNon/aAny custom properties or metadata associated with the channel.
API limits

To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.

Output

TypeDescription
Promise<Channel>Object returning the created channel metadata.

Basic usage

Create a public ask-support channel.

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