Send and receive messages

icon

Usage in Blueprints and C++


Requires Message Persistence

To store data about messages, you must enable Message Persistence for your app's keyset in the Admin Portal and set the desired message retention period.

Send

Send a message to a previously defined channel using the SendText() method.

SendText() prepares the final message content for publishing, including text, metadata, mentioned users, or referenced channels..

Method signature

Output

This method doesn't return any value.

Basic usage

Send the Hi Everyone! message to the support channel, and mark its high priority.

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
#include "JsonObjectConverter.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

UPubnubChannel* Channel = Chat->GetChannel("support");
// Set up the message and additional parameters
FString Message = "Hi Everyone!";

// Prepare the metadata to indicate high priority
TSharedPtr<FJsonObject> JsonMeta = MakeShareable(new FJsonObject);
show all 28 lines

Receive

To receive messages on a given channel, you must connect to the channel and start listening to message events.

Last updated on