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:
- Creates a channel with the
directtype - Sets channel membership for the channel owner
- Invites the other user and creates a membership with a
"pending"status (generates aninviteevent)
If a conversation between the two users already exists, the method returns that existing channel.
Receive messages
Call Connect() to start receiving messages on the channel.
Method signature
- C++ / Input parameters
- Blueprint
1Chat->CreateDirectConversation(
2 UPubnubChatUser* User,
3 FString ChannelID,
4 FPubnubChatChannelData ChannelData,
5 FPubnubChatMembershipData HostMembershipData = FPubnubChatMembershipData()
6);
| Parameter | Description |
|---|---|
User *Type: UPubnubChatUser* | User that you invite to join a channel. |
ChannelIDType: FString | 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. |
ChannelDataType: FPubnubChatChannelData | Information about the channel. This function overwrites the value of the Type field and always sets it to "direct". |
HostMembershipDataType: FPubnubChatMembershipData | The object containing all information about the user-channel membership. For more information, refer to FPubnubChatMembershipData. |
FPubnubChatChannelData
| Parameter | Description |
|---|---|
ChannelNameType: FStringDefault: n/a | Display name for the channel (must not be empty or consist only of whitespace characters). |
DescriptionType: FStringDefault: n/a | Detailed description of the channel's purpose or topic. |
CustomType: FStringDefault: n/a | JSON providing custom data about the channel. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the custom property is not recommended in SDKs. |
StatusType: FStringDefault: n/a | Tag that lets you categorize your app channels by their current state. The tag choice is entirely up to you and depends on your use case. Maximum length is 50 characters. |
TypeType: FStringDefault: n/a | Tag that lets you categorize your app channels by their functional roles. The tag choice is entirely up to you and depends on your use case. Maximum length is 50 characters. |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
| Parameter | Description |
|---|---|
FPubnubChatCreateDirectConversationResultType: struct | Returned object containing these fields: Result, Channel, HostMembership, and InviteeMembership. |
→ ResultType: FPubnubChatOperationResult | Operation result with Error (bool) and ErrorMessage (FString). |
→ ChannelType: UPubnubChatChannel* | Returned object containing the created channel metadata. |
→ HostMembershipType: UPubnubChatMembership* | Returned object containing the host (channel owner) membership. |
→ InviteeMembershipType: UPubnubChatMembership* | Returned object containing the invited user's membership. |
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Create a direct conversation with another user asynchronously.
Actor.h
1
Actor.cpp
1
Create group channel
Group channels enable multi-user conversations for team collaboration and community building. Access requires an invitation.
CreateGroupConversation() performs these actions:
- Creates a channel with the
grouptype - Sets channel membership for the channel owner
- Invites other users to join and creates memberships with a
"pending"status
Receive messages
Call Connect() to start receiving messages on the channel.
Method signature
- C++ / Input parameters
- Blueprint
1Chat->CreateGroupConversation(
2 TArray<UPubnubChatUser*> Users,
3 FString ChannelID,
4 FPubnubChatChannelData ChannelData,
5 FPubnubChatMembershipData HostMembershipData = FPubnubChatMembershipData()
6);
| Parameter | Description |
|---|---|
Users *Type: TArray<UPubnubChatUser*> | Array of users that you invite to join a channel. You can invite a maximum number of 100 users at once. |
ChannelIDType: FString | ID of the group channel. |
ChannelDataType: FPubnubChatChannelData | Information about the channel. If you don't provide the name, the channel will get the same name as id. This function overwrites the value of the Type field and always sets it to "group". |
HostMembershipDataType: FPubnubChatMembershipData | The object containing all information about the user-channel membership. For more information, refer to FPubnubChatMembershipData. |
Output
| Parameter | Description |
|---|---|
FPubnubChatCreateGroupConversationResultType: struct | Returned object containing these fields: Result, Channel, HostMembership, and InviteesMemberships. |
→ ResultType: FPubnubChatOperationResult | Operation result with Error (bool) and ErrorMessage (FString). |
→ ChannelType: UPubnubChatChannel* | Returned object containing the created channel metadata. |
→ HostMembershipType: UPubnubChatMembership* | Returned object containing the host (channel owner) membership. |
→ InviteesMembershipsType: TArray<UPubnubChatMembership*> | Returned object containing the invited users' memberships. |
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Create a group conversation and invite users to join asynchronously.
Actor.h
1
Actor.cpp
1
Other examples
Create group conversation with custom data
Actor.h
1
Actor.cpp
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 Connect() to start receiving messages on the channel.
Method signature
- C++ / Input parameters
- Blueprint
1Chat->CreatePublicConversation(
2 FString ChannelID,
3 FPubnubChatChannelData ChannelData
4);
| Parameter | Description |
|---|---|
ChannelIDType: FString | ID of the public channel. |
ChannelDataType: FPubnubChatChannelData | Information about the channel. If you don't provide the name, the channel will get the same name as id. This function overwrites the value of the Type field and always sets it to "public". |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
| Parameter | Description |
|---|---|
FPubnubChatChannelResultType: struct | Returned object containing Result (FPubnubChatOperationResult) and Channel (UPubnubChatChannel*). |
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Create a public channel asynchronously.
Actor.h
1
Actor.cpp
1
Other examples
Create public conversation with custom data
Actor.h
1
Actor.cpp
1