Interface Channel

Enables messages to be published and historic messages to be retrieved for a channel.

Hierarchy

  • Channel

Properties

annotations: RestAnnotations
name: string

The channel name.

presence: Presence

A Presence object.

push: PushChannel

A PushChannel object.

Methods

  • Appends data to an existing message. The supplied data field is appended to the previous message's data, while all other fields (name, extras) replace the previous values if provided.

    The channel must be configured to allow message appends, enabled by a rule.

    The supplied Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Parameters

    • message: Message

      A Message object containing a populated serial field and the data to append.

    • Optional operation: MessageOperation

      An optional MessageOperation object containing metadata about the append operation.

    • Optional options: PublishOptions

      Optional parameters to modify how the publish is made.

    Returns Promise<UpdateDeleteResult>

    A promise which, upon success, will be fulfilled with an UpdateDeleteResult object containing the serial of the new version of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    const result = await channel.appendMessage({ ...message, data: ' more text' });
    

    See

    https://ably.com/docs/pub-sub/api/javascript/rest/channel#append-message

  • Marks a message as deleted by publishing an update with an action of MESSAGE_DELETE. This does not remove the message from the server, and the full message history remains accessible.

    Uses patch semantics: non-null name, data, and extras fields in the provided message replace the corresponding fields in the existing message, while null fields are left unchanged. A deleted message keeps its previous data unless the delete explicitly sets data to an empty value.

    The channel must be configured to allow message deletes, enabled by a rule.

    The supplied Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Parameters

    Returns Promise<UpdateDeleteResult>

    A promise which, upon success, will be fulfilled with an UpdateDeleteResult object containing the serial of the new version of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    const result = await channel.deleteMessage(message);
    

    See

    https://ably.com/docs/pub-sub/api/javascript/rest/channel#delete-message

  • Retrieves the latest version of a specific message by its serial identifier.

    The channel must be configured to allow message updates, enabled by a rule.

    The supplied serial or Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Parameters

    • serialOrMessage: string | Message

      Either the serial identifier string of the message to retrieve, or a Message object containing a populated serial field.

    Returns Promise<Message>

    A promise which, upon success, will be fulfilled with a Message object representing the latest version of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    const message = await channel.getMessage(serial);
    

    See

    https://ably.com/docs/pub-sub/api/javascript/rest/channel#get-message

  • Retrieves all historical versions of a specific message, ordered by version. This includes the original message and all subsequent update, delete, or append operations.

    The supplied serial or Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Message versions exist only when the channel is configured to allow updating, deleting, or appending messages, enabled by a rule.

    Parameters

    • serialOrMessage: string | Message

      Either the serial identifier string of the message whose versions are to be retrieved, or a Message object containing a populated serial field.

    • Optional params: Record<string, any>

      Optional parameters sent as part of the query string.

    Returns Promise<PaginatedResult<Message>>

    A promise which, upon success, will be fulfilled with a PaginatedResult object containing an array of Message objects representing all versions of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    const versions = await channel.getMessageVersions(message);
    

    See

    https://ably.com/docs/pub-sub/api/javascript/rest/channel#get-message-versions

  • Publishes an update to an existing message with patch semantics. Non-null name, data, and extras fields in the provided message replace the corresponding fields in the existing message, while null fields are left unchanged.

    The channel must be configured to allow message updates, enabled by a rule.

    The supplied Message must carry a populated serial. A newly constructed Message has none, so the call rejects with an ErrorInfo.

    Parameters

    • message: Message

      A Message object containing a populated serial field and the fields to update.

    • Optional operation: MessageOperation

      An optional MessageOperation object containing metadata about the update operation.

    • Optional options: PublishOptions

      Optional parameters to modify how the publish is made.

    Returns Promise<UpdateDeleteResult>

    A promise which, upon success, will be fulfilled with an UpdateDeleteResult object containing the serial of the new version of the message. Upon failure, the promise will be rejected with an ErrorInfo object which explains the error.

    Example

    await channel.updateMessage({ ...message, data: 'edited text' });
    

    See

    https://ably.com/docs/pub-sub/api/javascript/rest/channel#update-message

Generated using TypeDoc