On this page

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:

icon

Usage in Blueprints and C++


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 direct channel 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 Connect() to start receiving messages on the channel.

Method signature

API limits

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

Output

ParameterDescription
FPubnubCreatedChannelWrapper
Type: FPubnubCreatedChannelWrapper
Returned object containing these fields: CreatedChannel, HostMembership, and InviteesMemberships.
 → CreatedChannelReturned object containing the updated channel metadata.
 → HostMembershipReturned object containing the updated host (channel owner) metadata.
 → InviteesMemberships
Type: 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 lines

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 group channel type
  2. Sets channel membership for the channel owner
  3. Invites other users to join
Receive messages

Call Connect() to start receiving messages on the channel.

Method signature

Output

ParameterDescription
FPubnubCreatedChannelWrapper
Type: FPubnubCreatedChannelWrapper
Returned object containing these fields: CreatedChannel, HostMembership, and InviteesMemberships.
 → CreatedChannelReturned object containing the updated channel metadata.
 → HostMembershipReturned object containing the updated host (channel owner) metadata.
 → InviteesMemberships
Type: 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 lines

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 public channel with the specified metadata.

Receive messages

Call Connect() to start receiving messages on the channel.

Method signature

API limits

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

Output

ParameterDescription
Channel
Type: 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
Last updated on