---
source_url: https://www.pubnub.com/docs/chat/chat-sdk/build/features/messages/updates
title: Manage message updates
updated_at: 2026-05-29T11:07:55.611Z
---

> 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


# Manage message updates

Edit messages and receive real-time update events.

:::note Requires Message Persistence
Enable [Message Persistence](https://youtu.be/qLMtbINWGig) in the [Admin Portal](https://admin.pubnub.com/).
:::

## Edit messages

`editText()` replaces an existing message's content.

### Method signature

##### Under the hood

`editText()` calls Message Actions API and the JavaScript SDK [addMessageAction()](https://www.pubnub.com/docs/sdks/javascript/api-reference/message-actions#add-message-reaction) method to mark the edited messages as `edited`.

This method takes the following parameters:

```ts
message.editText(
    newText: string
): Promise<Message>
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| newText | string | Yes |  | New/updated text that you want to add in place of the existing message. |

#### Output

| Type | Description |
| --- | --- |
| `Promise<Message>` | An updated message instance with an added `edited` action type. |

### Sample code

Correct the number of the support ticket you sent to `78398`.

```ts
await message.editText(
    "Your ticket number is 78398"
)
```

## Get message updates

Receive real-time updates when a [Message object](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/message) changes using the event-driven method:

* `onUpdated()` - fires when a message's content or reactions change

The method accepts a callback and returns an unsubscribe function.

### Method signature

```ts
message.onUpdated(
    callback: (message: Message) => void
): () => void
```

#### Input

| Parameter | Description |
| --- | --- |
| `callback` *Type: n/aDefault: n/a | Callback function invoked when the message changes. |
| `> message` *Type: `Message`Default: n/a | The updated [Message object](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/message). |

#### Output

| Type | Description |
| --- | --- |
| `() => void` | Function you can call to stop listening to message updates. |

### Sample code

Listen for updates on a specific message.

```ts
const channel = await chat.getChannel("support")
const message = await channel.getMessage("16200000000000000")

const stopUpdated = message.onUpdated((updated) => {
    console.log("Message updated:", updated.content.text)
})

// after some time...
stopUpdated()
```

## Get message updates (deprecated)

:::warning Deprecated
`streamUpdates()` is deprecated. Use [onUpdated()](#get-message-updates) instead. `streamUpdatesOn()` remains supported.
:::

Receive real-time updates when messages or [reactions](https://www.pubnub.com/docs/chat/chat-sdk/build/features/messages/reactions) change:

* `streamUpdates()` - updates for a single [Message object](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/message)
* `streamUpdatesOn()` - updates for multiple `Message` objects

Both return an unsubscribe function.

:::note Stream update behavior
* `streamUpdates()` returns the entire updated `Message` on each change
* `streamUpdatesOn()` returns the complete list of monitored messages on each change
:::

### Method signature

##### Under the hood

`streamUpdates()` and `streamUpdatesOn()` call Pub/Sub API and the JavaScript SDK [subscribe()](https://www.pubnub.com/docs/sdks/javascript/api-reference/publish-and-subscribe#subscribe) and [unsubscribe()](https://www.pubnub.com/docs/sdks/javascript/api-reference/publish-and-subscribe#unsubscribe) methods.

These methods take the following parameters:

* streamUpdates() 1message.streamUpdates(2 callback: (message: Message) => unknown3): () => void
* streamUpdatesOn() 1static Message.streamUpdatesOn(2 messages: Message[],3 callback: (messages: Message[]) => unknown4): () => void

#### Input

| Parameter | Required in `streamUpdates()` | Required in `streamUpdatesOn()` | Description |
| --- | --- | --- | --- |
| `messages`Type: `Message[]`Default: n/a | No | Yes | Array of [Message objects](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/message) for which you want to get updates on changed messages or message reactions. |
| `callback`Type: n/aDefault: n/a | Yes | Yes | Callback function passed as a parameter to both methods. It defines the custom behavior to be executed when detecting message or message reaction changes. |
| `> message`Type: `Message`Default: n/a | Yes | No | Returned `Message` object with the updated message or reactions. |
| `> messages`Type: `Message[]`Default: n/a | No | Yes | Returned array of `Message` objects with the updated messages or reactions. |

#### Output

| Type | Description |
| --- | --- |
| `() => void` | Function you can call to disconnect (unsubscribe) from the channel and stop receiving `objects` events. |

#### Errors

Whenever a list of `Message` objects is required as a parameter, and you try to get updates on messages and message actions without specifying the list, you will receive the `Cannot stream message updates on an empty list` error.

### Sample code

* streamUpdates() Get message and message reaction-related updates for the message with the timetoken 16200000000000000 published on the support channel. 1const channel = await chat.getChannel("support")2const message = await channel.getMessage("16200000000000000")3message.streamUpdates((message) => {4 // The callback receives the entire updated Message object (including all reactions)5 // each time a change occurs.6 console.log("Updated message: ", message)7})
* streamUpdatesOn() Get message and message reaction-related updates for the first page of messages published on the support channel. 1const channel = await chat.getChannel("support")2const { messages } = await channel.getHistory()3Message.streamUpdatesOn(messages, (messages) => {4 // The callback receives the complete list of all messages you're monitoring5 // each time any change occurs.6 console.log("Updated messages: ", messages)7})

### Other examples

* streamUpdates() Stop listening to updates for the message with the timetoken 16200000000000000 published on the support channel. 1const channel = await chat.getChannel("support")2const message = await channel.getMessage("16200000000000000")3const stopUpdates = message.streamUpdates(/* handle update callback */)4// after some time...5stopUpdates()
* streamUpdatesOn() Stop listening to updates for the last ten messages published on the support channel. 1const channel = await chat.getChannel("support")2const { messages } = await channel.getHistory()3const stopUpdates = Message.streamUpdatesOn(messages, /* handle updates callback */)4// after some time...5stopUpdates()