Retrieve channel history
Use thehistory() method to retrieve previously published messages:
History parameters
Customize your history query with the following parameters:| Parameter | Description |
|---|---|
| start | Earliest time in milliseconds since the epoch for any messages retrieved |
| end | Latest time in milliseconds since the epoch for any messages retrieved |
| direction | forwards or backwards (default: backwards) |
| limit | Maximum number of messages to retrieve per page, up to 1,000 (default: 100) |
Query by time range
Get messages in chronological order
Pagination
History results are paginated. Use thehasNext() and next() methods to iterate through pages:
Continuous history with rewind
Use the rewind channel option to get historical messages when attaching to a channel:Rewind by time
You can also rewind by time interval:History with untilAttach
Get continuous history up to the point of channel attachment:Message retention
How long messages are stored depends on your channel rules:| Storage Type | Default | Maximum |
|---|---|---|
| Ephemeral | 2 minutes | 2 minutes |
| Persisted (Free) | 24 hours | 24 hours |
| Persisted (Paid) | 72 hours | 365 days |
Presence history
You can also retrieve historical presence events:Best practices
Use history for catch-up only
History is designed for short-term catch-up, not as a primary data store:Limit history queries
Be specific about what you need:Use integrations for long-term storage
For long-term storage and complex queries, use integrations to send data to your own database:- Store messages in your database via webhooks
- Use message queues for processing
- Enable data warehousing for analytics
Next steps
- Learn about message storage options
- Explore rewind channel option
- Set up integrations for long-term storage
- Understand connection recovery
