Create channels

Channel naming

Before creating channels, take the time to carefully plan your naming strategy. 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 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.

No support for channel groups

Chat SDKs don't support channel groups. We recommend using a Core SDK to manage 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 for the channel owner
  3. Invites the other user (generates an invite event)

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

Receive messages

Call onMessageReceived() to start receiving messages on the channel (closure-based), or use channel.stream.messages() for an AsyncStream-based approach.

Method signature​

This method takes the following parameters:

1chat.createDirectConversation(
2 invitedUser: UserImpl,
3 channelId: String? = nil,
4 channelName: String? = nil,
5 channelDescription: String? = nil,
6 channelCustom: [String: JSONCodableScalar]? = nil,
7 channelStatus: String? = nil,
8 membershipCustom: [String: JSONCodableScalar]? = nil
9) async throws -> CreateDirectConversationResult<ChannelImpl, MembershipImpl>

Input​

required
invitedUser required#
Type: UserImpl
Default: no default
User that you invite to join a channel.
channelId#
Type: String
Default: 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.
channelName#
Type: String
Default: no default
Display name for the channel.

If you don't provide the name, the channel will get the same name as id (value of channelId).
channelDescription#
Type: String
Default: no default
Additional details about the channel.
channelCustom#
Type: [String: JSONCodableScalar]
Default: no default
Any custom properties or metadata associated with the channel 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.
channelStatus#
Type: String
Default: no default
Current status of the channel, like online, offline, or archived.
membershipCustom#
Type: [String: JSONCodableScalar]
Default: no default
Any custom properties or metadata associated with the user-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​

CreateDirectConversationResult#
Type: object
Returned object containing these fields: channel, hostMembership, and inviteeMembership.
 → channel#
Type: ChannelImpl
Returned object containing the updated channel metadata.
 → hostMembership#
Type: MembershipImpl
Returned object containing the updated host (channel owner) metadata.
 → inviteeMembership#
Type: MembershipImpl
Returned object containing the updated data of the invited user.

Sample code​

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

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

1

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 other users to join
Receive messages

Call onMessageReceived() to start receiving messages on the channel (closure-based), or use channel.stream.messages() for an AsyncStream-based approach.

Method signature​

This method takes the following parameters:

1chat.createGroupConversation(
2 invitedUsers: [UserImpl],
3 channelId: String? = nil,
4 channelName: String? = nil,
5 channelDescription: String? = nil,
6 channelCustom: [String: JSONCodableScalar]? = nil,
7 channelStatus: String? = nil,
8 membershipCustom: [String: JSONCodableScalar]? = nil
9) async throws -> CreateGroupConversationResult<ChannelImpl, MembershipImpl>

Input​

required
invitedUsers required#
Type: [UserImpl]
Default: no default
Users that you invite to join a channel.
channelId#
Type: String
Default: Automatically generated ID
ID of the group channel. The channel ID is created automatically using the v4 UUID generator. You can override it by providing your own ID.
channelName#
Type: String
Default: no default
Display name for the channel.

If you don't provide the name, the channel will get the same name as id (value of channelId).
channelDescription#
Type: String
Default: no default
Additional details about the channel.
channelCustom#
Type: [String: JSONCodableScalar]
Default: no default
Any custom properties or metadata associated with the channel 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.
channelStatus#
Type: String
Default: no default
Current status of the channel, like online, offline, or archived.
membershipCustom#
Type: [String: JSONCodableScalar]
Default: no default
Any custom properties or metadata associated with the user-channel memberships 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​

CreateGroupConversationResult#
Type: object
Returned object containing these fields: channel, hostMembership, and inviteeMemberships.
 → channel#
Type: ChannelImpl
Returned object containing the updated channel metadata.
 → hostMembership#
Type: MembershipImpl
Returned object containing the updated host (channel owner) data.
 → inviteeMemberships#
Type: [MembershipImpl]
Returned object containing the updated metadata of the invited users.

Sample code​

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

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

1

Create public channel​

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

Supported features

Public channels do not support typing indicators or read receipts. These features are impractical for large audiences.

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

Receive messages

Call onMessageReceived() to start receiving messages on the channel (closure-based), or use channel.stream.messages() for an AsyncStream-based approach.

Method signature​

This method takes the following parameters:

1chat.createPublicConversation(
2 channelId: String? = nil,
3 channelName: String? = nil,
4 channelDescription: String? = nil,
5 channelCustom: [String: JSONCodableScalar]? = nil,
6 channelStatus: String? = nil
7) async throws -> ChannelImpl

Input​

channelId#
Type: String
Default: Automatically generated UUIDv4
ID of the public channel. The channel ID is created automatically using the v4 UUID generator. You can override it by providing your own ID.
channelName#
Type: String
Default: no default
Display name for the channel.

If you don't provide the name, the channel will get the same name as id (value of channelId).
channelDescription#
Type: String
Default: no default
Additional details about the channel.
channelCustom#
Type: [String: JSONCodableScalar]
Default: no default
Any custom properties or metadata associated with the channel 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.
channelStatus#
Type: String
Default: no default
Current status of the channel, like online, offline, or archived.
API limits

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

Output​

ChannelImpl#
Object returning the created channel metadata.

Sample code​

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Create a public ask-support channel.

1

Was this page useful?

Last updated on