---
source_url: https://www.pubnub.com/docs/general/messages/overview
title: Message Basics
updated_at: 2026-05-25T11:26:18.318Z
---

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

The PubNub messaging system powers real-time data flow. It delivers and processes messages within milliseconds.

###### Deliver messages with Pub/Sub

Messages and signals are the data units that flow through PubNub's [Pub/Sub](https://www.pubnub.com/docs/general/channels/overview) system. When you publish a message or signal to a channel, PubNub delivers it to all subscribers of that channel in real time. Use messages for durable, full-payload delivery and [signals](https://www.pubnub.com/docs/general/messages/publish#messages-vs-signals) for lightweight ephemeral data like typing indicators or location pings.

## Send messages

Send messages with the [Publish API](https://www.pubnub.com/docs/sdks/rest-api/publish-introduction). It minimizes latency and maximizes delivery reliability across PubNub’s global network. You send to a single channel. Use JSON for structured data.

```javascript
pubnub.publish(
  {
    channel: "my_channel",
    message: {"text": "Hello World!"}
  },
  function(status, response) {
    console.log(status, response);
  }
);
```

Messages can include metadata for extra context. You can only [publish](https://www.pubnub.com/docs/general/messages/publish) to one channel at a time. For multi-channel operations, use [channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups).

The maximum [message size](https://www.pubnub.com/docs/general/setup/limits#publish) is 32 KiB. This includes the channel name and any metadata. Larger messages return an error. This protects performance and network usage.

### Signals

Signals are lightweight, one-way notifications. Use them for high-frequency, low-cost events like typing indicators or location pings. Signals do not support [Message Persistence](https://www.pubnub.com/docs/general/storage) or [Mobile Push Notifications](https://www.pubnub.com/docs/general/push/send).

See [Messages vs Signals](https://www.pubnub.com/docs/general/messages/publish#messages-vs-signals) for details.

## Receive messages

To [receive messages](https://www.pubnub.com/docs/general/messages/receive), add an event listener with your SDK. Handlers process message and presence events so your app can react quickly.

```javascript
const subscription = pubnub.channel('channel_1').subscription();
subscription.onMessage = (messageEvent) => { console.log("Message event: ", messageEvent); };
subscription.onPresence = (presenceEvent) => { console.log("Presence event: ", presenceEvent); };
```

Learn more about [channels](https://www.pubnub.com/docs/general/channels/overview), [presence](https://www.pubnub.com/docs/general/presence/overview), and [message history](https://www.pubnub.com/docs/general/storage).

###### Your message listener handles more than messages

The same listener receives [presence events](https://www.pubnub.com/docs/general/presence/presence-events#subscribe-to-presence-channel) (user join/leave) and [App Context](https://www.pubnub.com/docs/general/metadata/basics) change events (user, channel, or membership updates) alongside regular messages. Presence events arrive on dedicated `-pnpres` channels. App Context events arrive on the affected channels and on the user's own channel. See [Real-time updates](https://www.pubnub.com/docs/general/metadata/basics#real-time-updates) for App Context event types and delivery behavior.

###### Extend message delivery with persistence, files, and push

Messages are ephemeral in transit by default. Enable [Message Persistence](https://www.pubnub.com/docs/general/storage) to store messages and retrieve them later by timetoken, attach [message actions](https://www.pubnub.com/docs/general/messages/actions) to historical messages for reactions or receipts. [File Sharing](https://www.pubnub.com/docs/general/files) delivers files as a special message type (type `4`) on the same channel infrastructure. [Mobile Push Notifications](https://www.pubnub.com/docs/general/push/send) convert published messages into native push payloads for iOS and Android when users are not active in the app.

## Message actions

[Message actions](https://www.pubnub.com/docs/general/messages/actions) let you add actions, such as delivery acknowledgments or emoji reactions, after publish. You can add or remove these actions to improve user interaction, for example in [chat applications](https://www.pubnub.com/docs/chat/overview).

```javascript
pubnub.addMessageAction(
  {
    channel: 'chats.room1',
    messageTimetoken: '15610547826970040',
    action: {
      type: 'reaction',
      value: 'smiley_face',
    }
  },
  function(status, response) {
    console.log(status, response);
  }
);
```

###### Extend messages with server-side processing and analytics

Published messages integrate with several platform features beyond delivery. [Functions](https://www.pubnub.com/docs/serverless/functions/overview) can filter, transform, or enrich messages before or after they reach subscribers. [Events & Actions](https://www.pubnub.com/docs/serverless/events-and-actions/overview) can export message publish events to external systems like webhooks, Amazon S3, or Apache Kafka. For operational visibility, [Channel Monitor](https://www.pubnub.com/docs/bizops-workspace/channel-monitor) lets you view and moderate live message traffic. For analytics, [Illuminate](https://www.pubnub.com/docs/illuminate/basics) ingests message data to power real-time decisions and [Insights](https://www.pubnub.com/docs/pubnub-insights/basics) provides aggregate metrics on message traffic and types.

## Message types

Use descriptive [message types](https://www.pubnub.com/docs/general/messages/type) to categorize and process messages. Define a `custom_message_type` for every message to enable targeted handling and data management.

:::tip Filter by message type
You can use message types to filter messages using server-side [subscribe filters](https://www.pubnub.com/docs/general/channels/subscribe-filters).
:::

###### Secure message delivery with Access Manager

Access Manager controls who can publish and subscribe to channels. Publishing requires a `write` permission and subscribing requires a `read` permission on the target channel. Without a valid token, clients cannot send or receive messages. See [Access Manager permissions](https://www.pubnub.com/docs/general/security/access-control#operations-to-permissions-mapping) for the full operations-to-permissions mapping.

## Terms in this document

* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.
