Interface UseMessagesResponse

The response from the useMessages hook.

interface UseMessagesResponse {
    connectionError?: ErrorInfo;
    connectionStatus: ConnectionStatus;
    deleteMessage: ((message: Message, deleteMessageParams?: DeleteMessageParams) => Promise<Message>);
    get: ((options: QueryOptions) => Promise<PaginatedResult<Message>>);
    getPreviousMessages?: ((params: Omit<QueryOptions, "direction">) => Promise<PaginatedResult<Message>>);
    messages?: Messages;
    roomError?: ErrorInfo;
    roomStatus: RoomStatus;
    send: ((params: SendMessageParams) => Promise<Message>);
    update: ((message: Message, update: UpdateMessageParams, details?: ActionDetails) => Promise<Message>);
}

Hierarchy (view full)

Properties

connectionError?: ErrorInfo

If there's a connection error it will be available here.

connectionStatus: ConnectionStatus

Provides the connection status of the Ably connection.

deleteMessage: ((message: Message, deleteMessageParams?: DeleteMessageParams) => Promise<Message>)

A shortcut to the Messages.delete method.

Type declaration

    • (message, deleteMessageParams?): Promise<Message>
    • Delete a message in the chat room.

      This method uses the Ably Chat API REST endpoint for deleting messages. It performs a soft delete, meaning the message is marked as deleted.

      Note that the Promise may resolve before OR after the message is deleted from the realtime channel. This means you may see the message that was just deleted in a callback to subscribe before the returned promise resolves.

      Should you wish to restore a deleted message, and providing you have the appropriate permissions, you can simply send an update to the original message. Note: This is subject to change in future versions, whereby a new permissions model will be introduced and a deleted message may not be restorable in this way.

      Parameters

      • message: Message

        The message to delete.

      • OptionaldeleteMessageParams: DeleteMessageParams

        Optional details to record about the delete action.

      Returns Promise<Message>

      A promise that resolves when the message was deleted.

get: ((options: QueryOptions) => Promise<PaginatedResult<Message>>)

A shortcut to the Messages.get method.

Type declaration

    • (options): Promise<PaginatedResult<Message>>
    • Get messages that have been previously sent to the chat room, based on the provided options.

      Parameters

      Returns Promise<PaginatedResult<Message>>

      A promise that resolves with the paginated result of messages. This paginated result can be used to fetch more messages if available.

getPreviousMessages?: ((params: Omit<QueryOptions, "direction">) => Promise<PaginatedResult<Message>>)

Retrieves the previous messages in the room.

This method is available only if a MessageListener has been provided in the UseMessagesParams. Calling will return a promise that resolves to a paginated response of the previous messages received in the room, up until the listener was attached, in the oldest to newest order.

It is advised to call this method after any discontinuity event; to retrieve messages that may have been missed before the listener was re-attached.

This is removed when the component unmounts or when the previously provided listener is removed.

Type declaration

    • (params): Promise<PaginatedResult<Message>>
    • Get the previous messages that were sent to the room before the listener was subscribed.

      Parameters

      • params: Omit<QueryOptions, "direction">

        Options for the history query.

      Returns Promise<PaginatedResult<Message>>

      A promise that resolves with the paginated result of messages, in newest-to-oldest order.

The query options to use when fetching the previous messages.

messages?: Messages

Provides access to the underlying Messages instance of the room.

roomError?: ErrorInfo

If there's an error with the room it will be available here.

roomStatus: RoomStatus

Provides the status of the room.

send: ((params: SendMessageParams) => Promise<Message>)

A shortcut to the Messages.send method.

Type declaration

    • (params): Promise<Message>
    • Send a message in the chat room.

      This method uses the Ably Chat API endpoint for sending messages.

      Note that the Promise may resolve before OR after the message is received from the realtime channel. This means you may see the message that was just sent in a callback to subscribe before the returned promise resolves.

      Parameters

      • params: SendMessageParams

        an object containing {text, headers, metadata} for the message to be sent. Text is required, metadata and headers are optional.

      Returns Promise<Message>

      A promise that resolves when the message was published.

update: ((message: Message, update: UpdateMessageParams, details?: ActionDetails) => Promise<Message>)

A shortcut to the Messages.update method.

Type declaration

    • (message, update, details?): Promise<Message>
    • Update a message in the chat room.

      Note that the Promise may resolve before OR after the updated message is received from the realtime channel. This means you may see the update that was just sent in a callback to subscribe before the returned promise resolves.

      Parameters

      • message: Message

        The message to update.

      • update: UpdateMessageParams

        The new message content including headers and metadata. This fully replaces the old content. Everything that's not set will be removed.

      • Optionaldetails: ActionDetails

        Optional details to record about the update action.

      Returns Promise<Message>

      A promise of the updated message.