Interface Message

Represents a single message in a chat room.

interface Message {
    clientId: string;
    createdAt: Date;
    deletedAt?: Date;
    deletedBy?: string;
    headers: Headers;
    isDeleted: boolean;
    isUpdated: boolean;
    latestAction: ChatMessageActions;
    latestActionDetails?: MessageActionDetails;
    latestActionSerial: string;
    metadata: Metadata;
    roomId: string;
    serial: string;
    text: string;
    updatedAt?: Date;
    updatedBy?: string;
    actionAfter(message: Message): boolean;
    actionBefore(message: Message): boolean;
    actionEqual(message: Message): boolean;
    after(message: Message): boolean;
    before(message: Message): boolean;
    equal(message: Message): boolean;
}

Properties

clientId: string

The clientId of the user who created the message.

createdAt: Date

The timestamp at which the message was created.

deletedAt?: Date

The timestamp at which the message was deleted.

deletedBy?: string

The clientId of the user who deleted the message.

headers: Headers

The headers of a chat message. Headers enable attaching extra info to a message, which can be used for various features such as linking to a relative point in time of a livestream video or flagging this message as important or pinned.

Headers are part of the Ably realtime message extras.headers and they can be used for Filtered Subscriptions and similar.

This value is always set. If there are no headers, this is an empty object.

Do not use the headers for authoritative information. There is no server-side validation. When reading the headers treat them like user input.

isDeleted: boolean

Indicates if the message has been deleted.

isUpdated: boolean

Indicates if the message has been updated.

latestAction: ChatMessageActions

The latest action of the message. This can be used to determine if the message was created, updated, or deleted.

latestActionDetails?: MessageActionDetails

The details of the latest action that updated the message. This is only set for update and delete actions.

latestActionSerial: string

A unique identifier for the latest action that updated the message. This is only set for update and deletes.

metadata: Metadata

The metadata of a chat message. Allows for attaching extra info to a message, which can be used for various features such as animations, effects, or simply to link it to other resources such as images, relative points in time, etc.

Metadata is part of the Ably Pub/sub message content and is not read by Ably.

This value is always set. If there is no metadata, this is an empty object.

Do not use metadata for authoritative information. There is no server-side validation. When reading the metadata treat it like user input.

roomId: string

The roomId of the chat room to which the message belongs.

serial: string

The unique identifier of the message.

text: string

The text of the message.

updatedAt?: Date

The timestamp at which the message was updated.

updatedBy?: string

The clientId of the user who updated the message.

Methods

  • Determines if the action of this message is after the action of the given message.

    Parameters

    • message: Message

      The message to compare against.

    Returns boolean

    true if the action of this message is after the given message.

    ErrorInfo if both message serials do not match, or if latestActionSerial of either is invalid.

  • Determines if the action of this message is before the action of the given message.

    Parameters

    • message: Message

      The message to compare against.

    Returns boolean

    true if the action of this message is before the given message.

    ErrorInfo if both message serials do not match, or if latestActionSerial of either is invalid.

  • Determines if the action of this message is equal to the action of the given message.

    Parameters

    • message: Message

      The message to compare against.

    Returns boolean

    true if the action of this message is equal to the given message.

    ErrorInfo if both message serials do not match, or if latestActionSerial of either is invalid.

  • Determines if this message was created after the given message. This comparison is based on global order, so does not necessarily represent the order that messages are received in realtime from the backend.

    Parameters

    • message: Message

      The message to compare against.

    Returns boolean

    true if this message was created after the given message, in global order.

    ErrorInfo if serials of either message is invalid.

  • Determines if this message was created before the given message. This comparison is based on global order, so does not necessarily represent the order that messages are received in realtime from the backend.

    Parameters

    • message: Message

      The message to compare against.

    Returns boolean

    true if this message was created before the given message, in global order.

    ErrorInfo if serials of either message is invalid.

  • Determines if this message is equal to the given message.

    Parameters

    • message: Message

      The message to compare against.

    Returns boolean

    true if this message is equal to the given message.

    ErrorInfo if serials of either message is invalid.