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.
| Parameter | Description | Default |
|---|---|---|
| start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. | Earliest available message |
| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. | Current time |
| orderBy | The order in which to retrieve messages from; either oldestFirst or newestFirst. | newestFirst |
| limit | Maximum number of messages to be retrieved per page, up to 1,000. | 100 |
Understanding message ordering
TheorderBy parameter determines the messages retrieved and their return order:
| Order | Retrieves | Returns | Use case |
|---|---|---|---|
newestFirst (default) | Most recent messages | [newest, ..., oldest] | Standard chat application |
oldestFirst | Oldest messages from room start | [oldest, ..., newest] | Archives, exports, admin tools |
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.
| Parameter | Description | Default |
|---|---|---|
| start | Earliest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp equal to, or greater than, this value will be returned. | Earliest available message |
| end | Latest time to retrieve messages from, as a unix timestamp in milliseconds. Messages with a timestamp less than this value will be returned. | Current time |
| limit | Maximum number of messages to be retrieved per page, up to 1,000. | 100 |
