On this page

Send and receive messages

icon

Usage in Blueprints and C++


Asynchronous and synchronous method execution

Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.

  • Asynchronous methods (Async suffix) return void and take an optional delegate parameter that fires when the operation completes.

    1Channel->SendTextAsync("Hello", OnSendTextResponseDelegate, SendTextParams);

    You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatOperationResponseNative).

  • Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.

    1FPubnubChatOperationResult Result = Channel->SendText("Hello", SendTextParams);
Requires Message Persistence

Enable Message Persistence on your keyset in the Admin Portal to store messages.

Send

Use SendText() to send a message to a channel. The method handles text content, metadata, user mentions, and channel references.

Method signature

1Channel->SendText(
2 FString Message,
3 FPubnubChatSendTextParams SendTextParams = FPubnubChatSendTextParams()
4);

Input parameters

* required
ParameterDescription
Message *
Type: FString
Default:
n/a
Text that you want to send to the selected channel.
SendTextParams
Type: FPubnubChatSendTextParams
Default:
n/a
Struct providing additional parameters.
 → StoreInHistory
Type: bool
Default:
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
Type: bool
Default:
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
Type: FString
Default:
n/a
Publish additional details with the request.
Sending quoted messages

SendText() does not expose quoting directly. To send a quoted message, use a MessageDraft: call MessageDraft->SetQuotedMessage(QuotedMessage) before Draft->Send().

Output

TypeDescription
FPubnubChatOperationResult
Result of the operation. Check Error and ErrorMessage for failure.

Sample code

Reference code

This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.

Send a text message to a channel asynchronously.

Actor.h
1

Actor.cpp
1

Receive

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

Last updated on