---
source_url: https://www.pubnub.com/docs/sdks/c-sharp/api-reference/message-actions
title: Message Actions API for C# SDK
updated_at: 2026-06-17T11:38:52.037Z
sdk_name: PubNub C# SDK
sdk_version: 8.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 C# SDK

PubNub C# SDK, use the latest version: 8.3.0

Install:

```bash
dotnet add package PubNub@8.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 on demand 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.
:::

:::tip Request execution
Use `try`/`catch` when working with the C# SDK.
If a request has invalid parameters (for example, a missing required field), the SDK throws an exception. If the request reaches the server but fails (server error or network issue), the error details are available in the returned `status`.
```csharp
try
{
    PNResult<PNPublishResult> publishResponse = await pubnub.Publish()
        .Message("Why do Java developers wear glasses? Because they can't C#.")
        .Channel("my_channel")
        .ExecuteAsync();
    PNStatus status = publishResponse.Status;
    Console.WriteLine("Server status code : " + status.StatusCode.ToString());
}
catch (Exception ex)
{
    Console.WriteLine($"Request can't be executed due to error: {ex.Message}");
}
```
:::

## Add message action

:::warning Requires Message Persistence
Enable Message Persistence for your key in the [Admin Portal](https://admin.pubnub.com/) as described in the [support article](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

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

### Method(s)

Use this C# method:

```csharp
pubnub.AddMessageAction()
        .Channel(string)
        .MessageTimetoken(long)
        .Action(PNMessageAction)
```

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

#### 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;

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

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);

try
{
    pubnub.AddMessageAction()
        .Channel("my_channel")
        .MessageTimetoken(5610547826969050) // Replace with actual message timetoken
        .Action(new PNMessageAction { Type = "reaction", Value = "smiley_face" })
        .Execute(new PNAddMessageActionResultExt((result, status) =>
        {
            if (!status.Error && result != null)
            {
                Console.WriteLine("Message action added successfully.");
            }
            else
            {
                Console.WriteLine(pubnub.JsonPluggableLibrary.SerializeToJsonString(status));
            }
        }));
}
catch (Exception ex)
{
    Console.WriteLine($"Request cannot be executed due to error: {ex.Message}");
}
```

### Returns

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

## Remove message action

:::warning Requires Message Persistence
Enable Message Persistence for your key in the [Admin Portal](https://admin.pubnub.com/) as described in the [support article](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

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

### Method(s)

Use this C# method:

```csharp
pubnub.RemoveMessageAction()
        .Channel(string)
        .MessageTimetoken(long)
        .ActionTimetoken(long)
        .Uuid(string)
```

| Parameter | Description |
| --- | --- |
| `Channel` *Type: string | Channel name to remove the message action from. |
| `MessageTimetoken` *Type: long | Timetoken of the target message. |
| `ActionTimetoken` *Type: long | Timetoken of the message action to remove. |
| `Uuid` *Type: string | UUID of the message. |

### Sample code

```csharp
using PubnubApi;

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

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);

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
Enable Message Persistence for your key in the [Admin Portal](https://admin.pubnub.com/) as described in the [support article](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Get a list of message actions in a channel. The response sorts actions by the action 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 is returned with additional parameters. Send iterative calls to Message Persistence, adjusting the parameters to fetch more message actions.
:::

### Method(s)

Use this C# method:

```csharp
pubnub.GetMessageActions()
        .Channel(string)
        .Start(long)
        .End(long)
        .Limit(int)
```

| Parameter | Description |
| --- | --- |
| `Channel` *Type: stringDefault: n/a | Channel name to list message actions for. |
| `Start`Type: longDefault: n/a | Message action timetoken for the start of the range (exclusive). |
| `End`Type: longDefault: n/a | Message action timetoken for the end of the range (inclusive). |
| `Limit`Type: intDefault: 100 | Maximum number of actions to return. Default/Maximum is `100`. |

### Sample code

```csharp
using PubnubApi;

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

// Initialize PubNub
Pubnub pubnub = new Pubnub(pnConfiguration);

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

### Returns

```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.