Send and receive messages
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
- Blueprint
- C++ / Input parameters
Channel->SendText(
FString Message,
FSendTextParams SendTextParams = FSendTextParams()
);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Message | FString | No | n/a | Text that you want to send to the selected channel. |
SendTextParams | FSendTextParams | No | n/a | Struct providing additional parameters. |
→ StoreInHistory | bool | No | true | If true , the messages are stored in Message Persistence. If StoreInHistory is not specified, the Message Persistence configuration specified on the Admin Portal keyset is used. |
→ SendByPost | bool | No | false | When true , the SDK uses HTTP POST to publish the messages. The message is sent in the BODY of the request instead of the query string when HTTP GET is used. The messages are also compressed to reduce their size. |
→ Meta | FString | No | n/a | Publish additional details with the request. |
→ MentionedUsers | TMap<int, FPubnubMentionedUser> | No | n/a | Object mapping a mentioned user (FString ID , FString Name ) with the number of mention (nameOccurrenceIndex ) in the message: export type MessageMentionedUsers = { [nameOccurrenceIndex: number]: { id: string; name: string } } . For example, { 0: { id: 123, name: "Mark" }, 2: { id: 345, name: "Rob" } } means that Mark will be shown on the first mention in the message and Rob on the third. |
→ ReferencedChannels | TMap<int, FPubnubReferencedChannel> | No | n/a | Object mapping the referenced channel (FString ID , FString Name ) with the place where this reference (nameOccurrenceIndex ) was mentioned in the message: export type MessageReferencedChannels = { [nameOccurrenceIndex: number]: { id: string; name: string } } . For example, { 0: { id: 123, name: "Support" }, 2: { id: 345, name: "Off-topic" } } means that Support will be shown on the first reference in the message and Off-topic on the third. Refer to Reference channels for more details. |
→ TextLinks | TArray<FPubnubTextLink> | No | n/a | Returned array of FPubnubTextLink (int Start_Index = 0 , int End_Index = 0 , FString Link = "" ) that are shown as text in the message. |
→ QuotedMessage | UPubnubMessage* | No | n/a | Message object added to a message when you quote another message. This object stores the following info about the quoted message: { timetoken: quotedMessage.timetoken, text: quotedMessage.text, userId: quotedMessage.userId } , where timetoken is the time when the quoted message was published, text contains the original message content, and userId is the identifier of the user who published the quoted message. |
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 linesReceive
To receive messages on a given channel, you must connect
to the channel and start listening to message events.