---
source_url: https://www.pubnub.com/docs/sdks/unity/api-reference/message-actions
title: Message Actions API for Unity SDK
updated_at: 2026-06-11T11:37:43.083Z
sdk_name: PubNub Unity SDK
sdk_version: v9.3.0
---

> 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 Actions API for Unity SDK

PubNub Unity SDK, use the latest version: v9.3.0

Use message actions to add or remove metadata on published messages. Common uses include receipts and reactions. Clients subscribe to a channel to receive message action events. Clients can also fetch past message actions from Message Persistence, either independently or when fetching original messages.

:::tip Reactions
"Message Reactions" is a specific application of the Message Actions API for emoji or social reactions.
:::

:::note Message Actions vs. Message Reactions
**Message Actions** is the flexible, low-level API for adding any metadata to messages (read receipts, delivery confirmations, custom data), while **Message Reactions** specifically refers to using Message Actions for emoji/social reactions.
In PubNub [Core](https://www.pubnub.com/docs/sdks) and [Chat](https://www.pubnub.com/docs/chat/overview) SDKs, the same underlying Message Actions API is referred to as **Message Reactions** when used for emoji reactions - it's the same functionality, just different terminology depending on the use case.
:::

## Add message action

:::warning Requires Message Persistence
This method requires that Message Persistence is [enabled](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) for your key in the [Admin Portal](https://admin.pubnub.com/).
:::

Add an action to a published message. The response includes the added action.

### Method(s)

Use this Unity method:

```csharp
pubnub.AddMessageAction()
    .Channel(string)
    .MessageTimetoken(long)
    .Action(PNMessageAction)
    .Execute(System.Action<PNAddMessageActionResult, PNStatus>)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| Channel | string | Yes |  | Channel name to add the message action to. |
| MessageTimetoken | long | Yes |  | Timetoken of the target message. |
| Action | PNMessageAction | Yes |  | Message action payload. |
| Execute | System.Action | Yes |  | `System.Action` of type `PNAddMessageActionResult`. |
| ExecuteAsync | None | Optional |  | Returns `Task<PNResult<PNAddMessageActionResult>>`. |

#### PNMessageAction

| Parameter | Description |
| --- | --- |
| `Type` *Type: string | Message action type. |
| `Value` *Type: string | Message action value. |

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```csharp
using PubnubApi;
using PubnubApi.Unity;
using UnityEngine;

public class AddMessageActionExample : MonoBehaviour {
	// Reference to a pubnub manager previously setup in Unity Editor
	// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
	[SerializeField] private PNManagerBehaviour pubnubManager;

	// An editor-serialized string for the channel ID
	[SerializeField] private string channelId = "my_channel";

	// An editor-serialized timetoken for the message
	[SerializeField] private long messageTimetoken = 5610547826969050;

	private void Start() {
		// Getting a reference to the Pubnub instance
		var pubnub = pubnubManager.pubnub;

		// Note that you can also initialize Pubnub instance for Unity directly from code:
		/*
		PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
		{
			SubscribeKey = "demo",
			PublishKey = "demo",
		};
		Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);
		*/

		// Adding a message action (reaction) to a specified message
		pubnub.AddMessageAction()
			.Channel(channelId)
			.MessageTimetoken(messageTimetoken)
			.Action(new PNMessageAction { Type = "reaction", Value = "smiley_face" })
			.Execute((result, status) => {
				// Handling the result of the operation
				if (status.Error) {
					Debug.LogError($"Error adding message action: {status.ErrorData.Information}");
				} else {
					Debug.Log($"Successfully added message action: {pubnub.JsonPluggableLibrary.SerializeToJsonString(result)}");
				}
			});
	}
}
```

### Returns

The `AddMessageAction()` operation returns a `PNAddMessageActionResult` which contains the following properties:

| Property Name | Type | Description |
| --- | --- | --- |
| MessageTimetoken | long | Timetoken of the message to be associated with message action. |
| ActionTimetoken | long | Timetoken of the message action that will be associated with the message. |
| Action | PNMessageAction | Message action payload. |
| → Type | string | Type of the message action. |
| → Value | string | Value of the message action. |
| Uuid | string | UUID associated with the message action. |

```json
{
    "MessageTimetoken":15610547826969050,
    "ActionTimetoken":15610547826970050,
    "Action":{
        "type":"reaction",
        "value":"smiley_face"
    },
    "Uuid":"user-456"
}
```

## Remove message action

:::warning Requires Message Persistence
This method requires that Message Persistence is [enabled](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) for your key in the [Admin Portal](https://admin.pubnub.com/).
:::

Remove a previously added action from a published message. The response is empty.

### Method(s)

Use this Unity method:

```csharp
pubnub.RemoveMessageAction()
    .Channel(string)
    .MessageTimetoken(long)
    .ActionTimetoken(long)
    .Uuid(string)
    .Execute(System.Action<PNRemoveMessageActionResult, PNStatus>)
```

| Parameter | Description |
| --- | --- |
| `Channel` *Type: string | Channel name to remove the message action from. |
| `MessageTimetoken` *Type: long | Publish `timetoken` of the original `message`. |
| `ActionTimetoken` *Type: long | Publish `timetoken` of the message action to be removed. |
| `Uuid` *Type: string | `UUID` of the `message`. |
| `Execute` *Type: `System.Action` | `System.Action` of type `PNRemoveMessageActionResult`. |
| `ExecuteAsync`Type: None | Returns `Task<PNResult<PNRemoveMessageActionResult>>`. |

### Sample code

```csharp
using PubnubApi;
using PubnubApi.Unity;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);

// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
/*
[SerializeField] private PNManagerBehaviour pubnubManager;
Pubnub pubnub = pubnubManager.pubnub;
*/

pubnub.RemoveMessageAction()
    .Channel("my_channel")
    .MessageTimetoken(15701761818730000)
    .ActionTimetoken(15701775691010000)
    .Uuid("mytestuuid")
    .Execute(new PNRemoveMessageActionResultExt((result, status) =>
    {
        //empty result of type PNRemoveMessageActionResult.
    }));
```

### Returns

The `RemoveMessageAction()` operation returns no actionable data.

## Get message actions

:::warning Requires Message Persistence
This method requires that Message Persistence is [enabled](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) for your key in the [Admin Portal](https://admin.pubnub.com/).
:::

Get a list of message actions in a channel. Returns a list of actions sorted by the action's timetoken in ascending order.

:::note Truncated response
The number of message actions in the response may be truncated when internal limits are hit. If the response is truncated, a `more` property will be returned with additional parameters. Send iterative calls to Message Persistence adjusting the parameters to fetch more message actions.
:::

### Method(s)

Use this Unity method:

```csharp
pubnub.GetMessageActions()
    .Channel(string)
    .Start(long)
    .End(long)
    .Limit(int)
    .Execute(System.Action<PNGetMessageActionsResult, PNStatus>)
```

| Parameter | Description |
| --- | --- |
| `Channel` *Type: stringDefault: n/a | The `channel` name. |
| `Start`Type: longDefault: n/a | Message Action `timetoken` denoting the `start` of the range requested (return values will be greater than or equal to `start`). |
| `End`Type: longDefault: n/a | Message Action `timetoken` denoting the `end` of the range requested (return values will be less than `end`). |
| `Limit`Type: intDefault: 100 | Specifies the number of actions to return in response. Default/Maximum is `100`. |
| `Execute` *Type: `System.Action`Default: n/a | `System.Action` of type `PNGetMessageActionsResult`. |
| `ExecuteAsync`Type: NoneDefault: n/a | Returns `Task<PNResult<PNGetMessageActionsResult>>`. |

### Sample code

```csharp
using PubnubApi;
using PubnubApi.Unity;

// Configuration
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize PubNub
Pubnub pubnub = PubnubUnityUtils.NewUnityPubnub(pnConfiguration);

// If you're using Unity Editor setup you can get the Pubnub instance from PNManagerBehaviour
// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
/*
[SerializeField] private PNManagerBehaviour pubnubManager;
Pubnub pubnub = pubnubManager.pubnub;
*/

pubnub.GetMessageActions()
    .Channel("my_channel")
    .Execute(new PNGetMessageActionsResultExt((result, status) =>
    {
        //result is of type PNGetMessageActionsResult.
    }));
```

### Returns

The `GetMessageActions()` operations returns `PNGetMessageActionsResult` which contains the following properties:

| Property Name | Type | Description |
| --- | --- | --- |
| Message Actions | `List<PNMessageActionItem>` | List of Message Actions. |
| More | MoreInfo | Pagination information. |

The `PNMessageActionItem` has the following properties:

| Property Name | Type | Description |
| --- | --- | --- |
| → MessageTimetoken | long | Timetoken associated with the message. |
| → Action | PNMessageAction | Message Action payload. |
| → → Type | string | Type of the Message Action. |
| → → Value | string | Value of the Message Action. |
| → Uuid | string | `UUID` associated with the action. |
| → ActionTimetoken | long | Timetoken associated with the action. |

The `More` has the following properties:

| Property Name | Type | Description |
| --- | --- | --- |
| → → Start | long | Timetoken denoting the start of the requested range. |
| → → End | long | Timetoken denoting the end of the requested range. |
| → → Limit | int | Number of Message Actions returned in response. |

```json
{
    "MessageActions":
    [{
        "MessageTimetoken":15610547826969050,
    "Action":{
        "type":"reaction",
        "value":"smiley_face"
    },
    "Uuid":"pn-5903a053-592c-4a1e-8bfd-81d92c962968",
    "ActionTimetoken":15717253483027900
    }],
    "More": {
        "Start": 15610547826970050,
        "End": 15645905639093361,
        "Limit": 2
    }
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **Channel pattern** - A way to group and analyze channel data to track performance metrics like message counts and user engagement over time with PubNub Insights.