Manage message updates

Edit messages and receive real-time update events.

Requires Message Persistence

Edit messages​

editText() replaces an existing message's content.

Method signature​

icon

Under the hood


This method takes the following parameters:

1message.editText(
2 newText: string
3): Promise<Message>

Input​

* required
ParameterDescription
newText *
Type: string
Default:
n/a
New/updated text that you want to add in place of the existing message.

Output​

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

1await message.editText(
2 "Your ticket number is 78398"
3)

Get message updates​

Receive real-time updates when a Message object 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​

1message.onUpdated(
2 callback: (message: Message) => void
3): () => void

Input​

* required
ParameterDescription
callback *
Type: n/a
Default:
n/a
Callback function invoked when the message changes.
> message *
Type: Message
Default:
n/a
The updated Message object.

Output​

TypeDescription
() => voidFunction you can call to stop listening to message updates.

Sample code​

Listen for updates on a specific message.

1const channel = await chat.getChannel("support")
2const message = await channel.getMessage("16200000000000000")
3
4const stopUpdated = message.onUpdated((updated) => {
5 console.log("Message updated:", updated.content.text)
6})
7
8// after some time...
9stopUpdated()

Get message updates (deprecated)​

Deprecated

streamUpdates() is deprecated. Use onUpdated() instead. streamUpdatesOn() remains supported.

Receive real-time updates when messages or reactions change:

  • streamUpdates() - updates for a single Message object
  • streamUpdatesOn() - updates for multiple Message objects

Both return an unsubscribe function.

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​

icon

Under the hood


These methods take the following parameters:

  • streamUpdates()

    1message.streamUpdates(
    2 callback: (message: Message) => unknown
    3): () => void
  • streamUpdatesOn()

    1static Message.streamUpdatesOn(
    2 messages: Message[],
    3 callback: (messages: Message[]) => unknown
    4): () => void

Input​

ParameterRequired in streamUpdates()Required in streamUpdatesOn()Description
messages
Type: Message[]
Default:
n/a
NoYesArray of Message objects for which you want to get updates on changed messages or message reactions.
callback
Type: n/a
Default:
n/a
YesYesCallback 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
YesNoReturned Message object with the updated message or reactions.
> messages
Type: Message[]
Default:
n/a
NoYesReturned array of Message objects with the updated messages or reactions.

Output​

TypeDescription
() => voidFunction 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 monitoring
    5 // 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()

Was this page useful?

Last updated on