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.
Join() or Connect() to receive messages
Method signature
- Blueprint
- C++ / Input parameters
Chat->CreateDirectConversation(
UPubnubUser* User,
FString ChannelID,
FPubnubChatChannelData ChannelData,
FString MembershipData = ""
);
Parameter | Type | Required | Description |
---|---|---|---|
User | UPubnubUser | Yes | User that you invite to join a channel. |
ChannelID | FString | Yes | 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 | FPubnubChatChannelData | Yes | Information about the channel. |
MembershipData | FString | No | Information about the user-channel membership. |
FPubnubChatChannelData
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
ChannelName | FString | No | n/a | Display name for the channel (must not be empty or consist only of whitespace characters). |
Description | FString | No | n/a | Channel's identifier in an external system. You can use it to match id with a similar identifier from an external database. |
CustomDataJson | FString | No | 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. |
Status | FString | No | 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. |
Type | FString | No | 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 | Type | Description |
---|---|---|
FPubnubCreatedChannelWrapper | FPubnubCreatedChannelWrapper | Returned object containing these fields: CreatedChannel , HostMembership , and InviteesMemberships . |
→ CreatedChannel | UPubnubChannel* | Returned object containing the updated channel metadata. |
→ HostMembership | UPubnubMembership* | Returned object containing the updated host (channel owner) metadata. |
→ InviteesMemberships | TArray<UPubnubMembership*> | Returned object containing the updated data of the invited users. |
Basic usage
Invite agent-007
to a 1:1 conversation to talk about customer XYZ
.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
// First, create a user object for agent-007
FString UserID = "agent-007";
FPubnubChatUserData UserData;
UserData.UserName = "Agent 007";
// Create the user
UPubnubUser* InvitedUser = Chat->CreateUser(UserID, UserData);
show all 29 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.
Join() or Connect() to receive messages
Method signature
- Blueprint
- C++ / Input parameters
Chat->CreateGroupConversation(
TArray<UPubnubUser*> Users,
FString ChannelID,
FPubnubChatChannelData ChannelData,
FString MembershipData = ""
);
Parameter | Type | Required | Description |
---|---|---|---|
Users | TArray<UPubnubUser*> | Yes | Array of users that you invite to join a channel. You can invite a maximum number of 100 users at once. |
ChannelID | FString | Yes | ID of the group channel. |
ChannelData | FPubnubChatChannelData | Yes | Information about the channel. If you don't provide the name, the channel will get the same name as id . |
MembershipData | FString | Yes | Information about the user-channel membership. 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. |
Output
Parameter | Type | Description |
---|---|---|
FPubnubCreatedChannelWrapper | FPubnubCreatedChannelWrapper | Returned object containing these fields: CreatedChannel , HostMembership , and InviteesMemberships . |
→ CreatedChannel | UPubnubChannel* | Returned object containing the updated channel metadata. |
→ HostMembership | UPubnubMembership* | Returned object containing the updated host (channel owner) metadata. |
→ InviteesMemberships | TArray<UPubnubMembership*> | Returned object containing the updated data of the invited users. |
Basic usage
Create a group conversation and invite agent-007
and agent-008
to have weekly syncs on customer XYZ
.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
// Get the GameInstance and Chat subsystem
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
// Create user objects for agent-007 and agent-008
FString UserID_007 = "agent-007";
FPubnubChatUserData UserData_007;
UserData_007.UserName = "Agent 007";
UPubnubUser* InvitedUser_007 = Chat->CreateUser(UserID_007, UserData_007);
FString UserID_008 = "agent-008";
show all 35 linesCreate public channel
Supported features
The public channel type comes with certain limitations in place - you'll get errors when trying to implement such Unreal 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.
Join() or Connect() to receive messages
Method signature
- Blueprint
- C++ / Input parameters
Chat->CreatePublicConversation(
FString ChannelID,
FPubnubChatChannelData ChannelData
);
Parameter | Type | Required | Description |
---|---|---|---|
ChannelID | FString | Yes | ID of the group channel. |
ChannelData | FPubnubChatChannelData | Yes | 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 | Type | Description |
---|---|---|
Channel | UPubnubChannel* | Object returning the created channel metadata. |
Basic usage
Create a public ask-support
channel.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
// Define the conversation/channel ID
FString ChannelID = "ask-support";
// Define the channel data
FPubnubChatChannelData ChannelData;
ChannelData.ChannelName = "ask-support";
ChannelData.Description = "Space dedicated to answering all support-related questions";
show all 18 lines