ReadRealm’s chat feature lets readers discuss any book in real time. Each book has its own chat room identified byDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/aliammari1/readrealm/llms.txt
Use this file to discover all available pages before exploring further.
bookId. Chat is primarily WebSocket-based — there are no REST endpoints for sending or receiving messages live.
For the full WebSocket event reference (joining rooms, sending messages, receiving broadcasts), see WebSockets.
How it works
When a user connects to a chat room over WebSocket:- The client emits a
joinRoomevent with abookId. - The server calls
ChatService.getRoomMessages(bookId)and immediately emits the last 50 messages back to the joining client. - Subsequent messages sent in the room are broadcast to all connected clients in real time.
- Every message emitted by a client is persisted to MongoDB via
ChatService.saveMessage().
Message persistence
Messages are stored in MongoDB using theMessage schema. The service exposes two operations used internally by the WebSocket gateway:
saveMessage(message)— persists a new message.getRoomMessages(bookId)— retrieves the last 50 messages for a room, sorted bycreatedAtdescending.
Message object
All chat messages share the following structure:Numeric ID of the book whose room this message belongs to. Matches the
id field in the Books API.Display name of the sender at the time the message was sent.
Text body of the message.
ISO 8601 timestamp added automatically by MongoDB (
timestamps: true).ISO 8601 timestamp of last modification, added automatically by MongoDB.
Example message payload
Room history on join
When a client joins a room, the server replays history. The client receives apreviousMessages event containing an array of up to 50 recent messages in the room, ordered newest-first.
This lets a user who joins mid-conversation catch up on context without any additional API calls.
Continue reading
WebSocket reference
Full event names, payloads, and connection flow for the real-time chat gateway.