The messages endpoints expose the persistent layer of TalkBox’s chat system. They let you create message records, retrieve every message you have sent or received, and load the full history of a one-to-one conversation. All three routes are protected — every request must include a valid Bearer token. For real-time delivery the TalkBox server also broadcasts messages over Socket.IO; the HTTP endpoint is best used for persisting messages or loading history on initial page load. All endpoints below require the following header:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/abdelhafid37/talkbox/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/messages
Creates a newMessage document in MongoDB. The authenticated user is automatically set as the sender; only receiver and content must be provided in the request body. The content string is trimmed before storage.
While this endpoint persists messages to the database, TalkBox uses Socket.IO as the primary real-time delivery channel. In a typical flow the client emits a socket event that both saves the message and pushes it to the recipient instantly. Use this HTTP endpoint when you need direct REST-based message creation.
Request body
The MongoDB ObjectId (24-character hex string) of the user who will receive the message.
The text content of the message. Whitespace is trimmed from both ends. An empty string after trimming is rejected with
400.Success response — 201 Created
The full Message document as stored in MongoDB:
The unique MongoDB ObjectId of the created message.
The ObjectId of the user who sent the message (derived from the JWT — not the request body).
The ObjectId of the intended recipient, as supplied in the request body.
The trimmed text content of the message.
ISO 8601 timestamp of when the document was created (added automatically by Mongoose
timestamps).ISO 8601 timestamp of the last update (added automatically by Mongoose
timestamps).Error responses
| Status | Condition |
|---|---|
400 Bad Request | receiver or content is missing, not a string, or content is empty after trimming |
401 Unauthorized | The Authorization header is absent, malformed, or the token is invalid |
500 Internal Server Error | An unexpected server or database error occurred |
Example
GET /api/messages
Returns everyMessage document where the authenticated user is either the sender or the receiver. This gives a complete inbox/outbox view. Documents are returned in default MongoDB order (insertion order) and are not populated — sender and receiver fields are raw ObjectIds.
Request body
None.Success response — 200 OK
An array of Message documents. Returns an empty array [] if the user has no messages.
Error responses
| Status | Condition |
|---|---|
401 Unauthorized | The Authorization header is absent, malformed, or the token is invalid |
500 Internal Server Error | An unexpected server or database error occurred |
Example
GET /api/messages/:userId
Returns the full chronological conversation history between the authenticated user and another user identified by the:userId path parameter. The query matches all messages where one participant is the caller and the other is :userId, sorted by createdAt ascending (oldest first). The sender and receiver fields are populated with the referenced user’s _id and username.
Path parameters
The MongoDB ObjectId (24-character hex string) of the other participant in the conversation.
Request body
None.Success response — 200 OK
An array of populated Message documents sorted oldest-first. Returns an empty array [] if no messages exist between the two users.
The unique MongoDB ObjectId of the message.
The populated sender user object.
The populated receiver user object.
The trimmed text content of the message.
ISO 8601 creation timestamp. Messages are sorted by this field in ascending order.
ISO 8601 last-updated timestamp.
Error responses
| Status | Condition |
|---|---|
400 Bad Request | The :userId path parameter is missing or not a string |
401 Unauthorized | The Authorization header is absent, malformed, or the token is invalid |
500 Internal Server Error | An unexpected server or database error occurred |