---
source_url: https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/history
title: Message history
updated_at: 2026-05-22T11:04:43.453Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Message history

PubNub APIs let you effectively fetch historical messages from direct, group, or public conversations.

While [App Context API](https://www.pubnub.com/docs/general/metadata/basics) lets you manage metadata and relationships between users and channels, enabling efficient tracking of which channels are associated with a given user, [Message Persistence API](https://www.pubnub.com/docs/general/storage) lets you retrieve messages from those channels. Together, these APIs enable you to gather all conversations involving a user and easily fetch specific message histories for any interactions between users.

Use `GetHistory()` to fetch past messages from a channel.

:::note API limitation
Results cannot be filtered by message type. All messages within the specified timeframe are returned.
:::

##### Usage in Blueprints and C++

You can use PubNub's functionality via Blueprints or directly in C++ code.

* In Blueprints, you can access PubNub from any Widget or Actor. Start by [initializing chat](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/configuration#initialize-pubnub-chat) using `InitChat` on `UPubnubChatSubsystem`. Afterwards, you can use the returned `UPubnubChat` object reference to call all Chat SDK functions.

:::warning Blueprint functions
The Blueprints provided in the documentation show how you can structure your application and may contain utility methods and elements like buttons that are not part of the Unreal Chat SDK and are meant to serve as guidance.
:::

* In C++, you can use UPubnubChatSubsystem as any other Game Instance Subsystem. #include "Kismet/GameplayStatics.h" #include "Engine/GameInstance.h" #include "PubnubChatSubsystem.h" // ACTION REQUIRED: Replace ASample_ChatSubsystem with name of your Actor class void ASample_ChatSubsystem::InitChatSample() { // Get PubnubChatSubsystem from GameInstance UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this); UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>(); // Initialize Chat - InitChat may fail under some conditions so make sure to check the Result for errors before using the Chat FPubnubChatInitChatResult InitChatResult = PubnubChatSubsystem->InitChat(TEXT("demo"), TEXT("demo"), TEXT("Player_001")); UPubnubChat* PubnubChat = InitChatResult.Chat; } Chat now allows you to call all Chat SDK functions, for example, Chat->GetChannel("my_channel").

:::note 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->GetHistoryAsync(StartTimetoken, EndTimetoken, OnGetHistoryResponseDelegate); You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatGetHistoryResponseNative).
* Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly. 1FPubnubChatGetHistoryResult Result = Channel->GetHistory(StartTimetoken, EndTimetoken);
:::

### Method signature

#### C++ / Input parameters

```cpp
Channel->GetHistory(
    FString StartTimetoken,
    FString EndTimetoken,
    int Count = 25
);
```

#### Blueprint

#### Input parameters

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| StartTimetoken | FString | Yes |  | [Timetoken](https://www.pubnub.com/docs/sdks/javascript/api-reference/misc#time) delimiting the start of a time slice (exclusive) to pull messages from. For details, refer to the [Fetch History section](https://www.pubnub.com/docs/sdks/javascript/api-reference/storage-and-playback#fetch-history). |
| EndTimetoken | FString | Yes |  | Timetoken delimiting the end of a time slice (inclusive) to pull messages from. For details, refer to the [Fetch History section](https://www.pubnub.com/docs/sdks/javascript/api-reference/storage-and-playback#fetch-history). |
| Count | int | Optional | `25` | Number of historical messages to return for the channel in a single call. Default is `25`. Since each call returns all attached [message reactions](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/reactions) by default, it is recommended to keep this value low; the server supports up to `100` messages per request. |

#### Output

| Field | Type | Description |
| --- | --- | --- |
| `Result` | `FPubnubChatOperationResult` | Operation result with `Error` and `ErrorMessage`. |
| `Messages` | `TArray<UPubnubChatMessage*>` | Array listing the requested number of historical [Message objects](https://www.pubnub.com/docs/chat/unreal-chat-sdk/learn/chat-entities/message). |
| `IsMore` | `bool` | Indicates if more messages exist beyond the returned range. |

By default, each call returns all message reactions and metadata attached to the retrieved messages.

### Sample code

:::tip 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.
:::

Retrieve message history for a channel asynchronously.

###### C++

###### Actor.h

```cpp
// blueprint.1lwvd0mh
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatChannel")
void GetHistorySample();

UFUNCTION()
void OnGetHistoryResponse(const FPubnubChatGetHistoryResult& Result);
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
void ASample_ChatChannel::GetHistorySample()
{
	// snippet.hide
	UPubnubChatChannel* Channel = nullptr;
	// snippet.show

	// Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)

	// Start timetoken (inclusive); must be higher (newer) than EndTimetoken (17-digit PubNub timetoken)
	FString StartTimetoken = TEXT("17800000000000000");
	// End timetoken (inclusive); must be lower (older) than StartTimetoken
	FString EndTimetoken = TEXT("17200000000000000");

	// Callback for when the operation completes (returns messages and IsMore)
	FOnPubnubChatGetHistoryResponseNative Callback;
	// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
	Callback.BindUObject(this, &ASample_ChatChannel::OnGetHistoryResponse);
	Channel->GetHistoryAsync(StartTimetoken, EndTimetoken, Callback);
}

// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
void ASample_ChatChannel::OnGetHistoryResponse(const FPubnubChatGetHistoryResult& Result)
{
	if (Result.Result.Error) { return; }
	TArray<UPubnubChatMessage*> Messages = Result.Messages;
	bool bIsMore = Result.IsMore;
}
```

###### Blueprint