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:
- Creates a
direct
(one-on-one) channel type. - Sets channel membership for the channel owner (so that they can join the channel).
- 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
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 linesInput
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
user | User | Yes | n/a | User that you invite to join a channel. |
channelId | string | No | 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 | No | n/a | Information about the channel. |
→ name | string | Channel ID | n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as id (value of channelId ). |
→ description | string | No | n/a | Additional details about the channel. |
→ custom | any | No | n/a | Any custom properties or metadata associated with the channel. |
membershipData | object | No | n/a | Information about the user-channel membership. |
→ custom | ObjectCustom | Yes | 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 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
Parameter | Type | Description |
---|---|---|
Promise<> | object | Returned object containing these fields: channel , hostMembership , and inviteeMembership . |
→ channel | Channel | Returned object containing the updated channel metadata. |
→ hostMembership | Membership | Returned object containing the updated host (channel owner) metadata. |
→ inviteeMembership | Membership | Returned 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 linesCreate 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:
- Creates a
group
channel type. - Sets channel membership for the channel owner (so that they can join the channel).
- 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
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 linesInput
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
users | User[] | Yes | 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 that the inviteMultiple() method calls. |
channelId | string | No | Automatically generated UUIDv4 | ID of the group channel. The channel ID is created automatically using the UUIDv4 module. You can override it by providing your own ID. |
channelData | object | No | n/a | Information about the channel. |
→ name | string | Channel ID | n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as id (value of channelId ). |
→ description | string | No | n/a | Additional details about the channel. |
→ custom | any | No | n/a | Any custom properties or metadata associated with the channel. |
membershipData | object | No | n/a | Information about the user-channel memberships. |
→ custom | ObjectCustom | Yes | 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 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
Parameter | Type | Description |
---|---|---|
Promise<> | object | Returned object containing these fields: channel , hostMembership , and inviteeMembership . |
→ channel | Channel | Returned object containing the updated channel metadata. |
→ hostMembership | Membership | Returned object containing the updated host (channel owner) data. |
→ inviteesMemberships | Membership[] | 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 linesCreate 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
This method takes the following parameters:
chat.createPublicConversation({ channelId, channelData, }: {
channelId?: string
channelData?: {
name?: string,
description?: string,
custom?: ObjectCustom
}
}): Promise<Channel>
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channelId | string | No | Automatically generated UUIDv4 | ID of the public channel. The channel ID is created automatically using the UUIDv4 module. You can override it by providing your own ID. |
channelData | object | No | n/a | Information about the channel. |
→ name | string | Channel ID | n/a | Display name for the channel. If you don't provide the name, the channel will get the same name as id (value of channelId ). |
→ description | string | No | n/a | Additional details about the channel. |
→ custom | any | No | n/a | Any 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
Type | Description |
---|---|
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"
}
}
)