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
directchannel type - Sets channel membership for the channel owner
- Invites the other user (generates an
inviteevent)
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
- Blueprint
- C++ / Input parameters
1Chat->CreateDirectConversation(
2 UPubnubUser* User,
3 FString ChannelID,
4 FPubnubChatChannelData ChannelData,
5 FPubnubChatMembershipData MembershipData = FPubnubChatMembershipData()
6);
| Parameter | Description |
|---|---|
User *Type: UPubnubUser | User that you invite to join a channel. |
ChannelID *Type: 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. |
ChannelData *Type: FPubnubChatChannelData | Information about the channel. |
FPubnubChatMembershipDataType: 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 | Channel's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
CustomDataJsonType: 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. |
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. |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
| Parameter | Description |
|---|---|
FPubnubCreatedChannelWrapperType: FPubnubCreatedChannelWrapper | Returned object containing these fields: CreatedChannel, HostMembership, and InviteesMemberships. |
→ CreatedChannelType: UPubnubChannel* | Returned object containing the updated channel metadata. |
→ HostMembershipType: UPubnubMembership* | Returned object containing the updated host (channel owner) metadata. |
→ InviteesMembershipsType: TArray<UPubnubMembership*> | Returned object containing the updated data of the invited users. |
Sample code
Invite agent-007 to a 1:1 conversation to talk about customer XYZ.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
8
9// First, create a user object for agent-007
10FString UserID = "agent-007";
11FPubnubChatUserData UserData;
12UserData.UserName = "Agent 007";
13
14// Create the user
15UPubnubUser* InvitedUser = Chat->CreateUser(UserID, UserData);
show all 29 linesCreate group channel
Group channels enable multi-user conversations for team collaboration and community building. Access requires an invitation.
CreateGroupConversation() performs these actions:
- Creates a
groupchannel type - Sets channel membership for the channel owner
- Invites other users to join
Receive messages
Call Connect() to start receiving messages on the channel.
Method signature
- Blueprint
- C++ / Input parameters
1Chat->CreateGroupConversation(
2 TArray<UPubnubUser*> Users,
3 FString ChannelID,
4 FPubnubChatChannelData ChannelData,
5 FPubnubChatMembershipData MembershipData = FPubnubChatMembershipData()
6);
| Parameter | Description |
|---|---|
Users *Type: TArray<UPubnubUser*> | Array of users that you invite to join a channel. You can invite a maximum number of 100 users at once. |
ChannelID *Type: FString | ID of the group channel. |
ChannelData *Type: FPubnubChatChannelData | Information about the channel. If you don't provide the name, the channel will get the same name as id. |
MembershipData *Type: FPubnubChatMembershipData | The object containing all information about the user-channel membership. For more information, refer to FPubnubChatMembershipData. |
Output
| Parameter | Description |
|---|---|
FPubnubCreatedChannelWrapperType: FPubnubCreatedChannelWrapper | Returned object containing these fields: CreatedChannel, HostMembership, and InviteesMemberships. |
→ CreatedChannelType: UPubnubChannel* | Returned object containing the updated channel metadata. |
→ HostMembershipType: UPubnubMembership* | Returned object containing the updated host (channel owner) metadata. |
→ InviteesMembershipsType: TArray<UPubnubMembership*> | Returned object containing the updated data of the invited users. |
Sample code
Create a group conversation and invite agent-007 and agent-008 to have weekly syncs on customer XYZ.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4// Get the GameInstance and Chat subsystem
5UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
6UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
7UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
8
9// Create user objects for agent-007 and agent-008
10FString UserID_007 = "agent-007";
11FPubnubChatUserData UserData_007;
12UserData_007.UserName = "Agent 007";
13UPubnubUser* InvitedUser_007 = Chat->CreateUser(UserID_007, UserData_007);
14
15FString UserID_008 = "agent-008";
show all 37 linesCreate 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 public channel with the specified metadata.
Receive messages
Call Connect() to start receiving messages on the channel.
Method signature
- Blueprint
- C++ / Input parameters
1Chat->CreatePublicConversation(
2 FString ChannelID,
3 FPubnubChatChannelData ChannelData
4);
| Parameter | Description |
|---|---|
ChannelID *Type: FString | ID of the group channel. |
ChannelData *Type: FPubnubChatChannelData | Information about the channel. If you don't provide the name, the channel will get the same name as id. |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
| Parameter | Description |
|---|---|
ChannelType: UPubnubChannel* | Object returning the created channel metadata. |
Sample code
Create a public ask-support channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
8
9// Define the conversation/channel ID
10FString ChannelID = "ask-support";
11
12// Define the channel data
13FPubnubChatChannelData ChannelData;
14ChannelData.ChannelName = "ask-support";
15ChannelData.Description = "Space dedicated to answering all support-related questions";
show all 18 lines