Every message is redundantly stored across multiple isolated datacenters before acknowledgment, ensuring your chat history is always available when you need it.
Retrieve previously sent messages
Use themessages.history() method to retrieve messages that have been previously sent to a room. This returns a paginated response, which can be queried further to retrieve the next set of messages.
Understanding message ordering
TheorderBy parameter determines the messages retrieved and their return order:
For the majority of chat UIs, the default behavior of
newestFirst will be correct. This retrieves messages from most recent to oldest, which you can then reverse to display the newest message at the bottom of the UI.
Retrieve messages sent prior to subscribing
Retrieve historical messages sent before subscribing usinghistoryBeforeSubscribe(). Messages are returned in order, from the most recent to the oldest (newestFirst). This is useful for providing conversational context when a user joins or rejoins a room, ensuring continuous message history without overlap.
Use the historyBeforeSubscribe() function returned as part of a message subscription response to only retrieve messages that were received before the listener was subscribed to the room. This returns a paginated response, which can be queried further to retrieve the next set of messages.
