---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/send-receive
title: Send and receive messages
updated_at: 2026-06-19T11:35:22.813Z
---

> 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


# Send and receive messages

:::note Requires Message Persistence
Enable [Message Persistence](https://youtu.be/qLMtbINWGig) on your keyset in the [Admin Portal](https://admin.pubnub.com/) to store messages.
:::

## Send

Use `SendText()` to send a [message](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/message) to a channel. The method handles text content and metadata. To send messages with user mentions, quoted messages, or file attachments, use [MessageDraft](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts) instead.

### Method signature

These methods take the following parameters:

```csharp
channel.SendText(string message)
```

```csharp
channel.SendText(string message, SendTextParams sendTextParams)
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| message | string | Yes |  | Text that you want to send to the selected channel. |
| sendTextParams | SendTextParams | Optional | `new SendTextParams()` | Parameters to configure sending options. |
| > storeInHistory | bool | Optional | `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 | Optional | `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 | Dictionary<string, | Optional | `new()` | Publish additional details with the request. |
| > customPushData | Dictionary<string, | Optional | `new()` | Custom key-value pairs to include in push notification payloads. Use this to send additional data along with your push notifications. Refer to [Mobile Push Notifications](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/push-notifications#send-custom-push-data) for more details. |

:::info Mentions, quotes, and files
To send a message with [user mentions](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/mentions), a [quoted message](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/quotes), or [file attachments](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/files), use [MessageDraft](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts) and call `draft.Send()`. These features are set directly on the `MessageDraft` object and are not available through `SendTextParams`.
:::

#### Output

An awaitable `Task`.

### Sample code

Send the `Hi Everyone!` message to the `support` channel.

```csharp
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

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

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// reference the channel where you want to send a text message
var channelResult = await chat.GetChannel("support");
if (channelResult.Error)
{
    Debug.Log("Couldn't find channel!");
    return;
}
var channel = channelResult.Result;

await channel.SendText("Hi everyone!");
```

### Other examples

For examples on how to send a message with [links](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/links), [mentioned users](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/mentions), [referenced channels](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/references), [message quotes](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/quotes), or [files](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/files), head to the relevant docs.

## Receive

To receive messages on a given channel, you must [connect to the channel](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/watch) and start listening to message events.