Skip to Content
HomeLink Hub
Chat

Send a message

POST
/api/v1/chat/rooms/{roomId}/messages

Access: Bearer token required.

Appends a message to the room and updates the room's lastMessage, lastMessageAt and lastMessageSenderId. The saved message is broadcast over Socket.IO as chat:message to the room channel room:<roomId> (sockets that sent chat:join for the room), with an added sender: { id, username }; unlike messages sent through the socket, this broadcast has no roomId field and no chat:room_updated event is sent to participants' personal rooms. Other participants who are offline (no socket and no SSE connection) get a push notification and, at most once per room every 30 minutes, an email ("New message from on HomeLink Hub"); chat messages are never stored in the notifications list. Those alerts follow agentMessages preferences for the room creator and newMessages for everyone else. Only participants of the room can post; anyone else, and any unknown or deleted room id, gets a 403. The handler does not validate content or messageType (the update is applied without schema validators), so send a non-empty content and one of the documented types. data is the saved message with senderId populated (firstName, lastName, avatar).

Envelope: chat endpoints do not use the standard {status, success, message, data} wrapper. Success bodies are {success, data} and the handler's own 400s are {success: false, message}; only errors that fall through to the global error middleware get the standard error envelope.

Authorization

bearerAuth
headerAuthorizationBearer <JWT>

Access token returned by sign-in. Send it as Authorization: Bearer <token>.

Path Parameters

roomId*string

ObjectId of the chat room.

Request Body

application/json
  1. body
content*string

Message text, or the URL of the uploaded media for non-text types. The model's limit is 5000 characters. Not validated by the handler.

messageType?string

TEXT (default), IMAGE, FILE or AUDIO. For non-text types the offline alert preview reads "Sent a photo", "Sent a file" or "Sent a voice note".

replyToId?string

ObjectId of the message being replied to. Stored as-is; not checked against the room.

Response Body

Message saved and broadcast

application/json
  1. response
success*boolean
data*
Example Request
curl -X POST 'http://localhost:4000/api/v1/chat/rooms/string/messages' \  -H 'Content-Type: application/json' \  -d '{  "content": "Good afternoon, is the flat still available for inspection this Saturday?",  "messageType": "TEXT"}'
Example Response
{  "success": true,  "data": {    "senderId": {      "_id": "665f1c2e9b1d4a0012ab34c4",      "firstName": "Amaka",      "lastName": "Eze",      "avatar": "https://res.cloudinary.com/example/image/upload/v1717500000/homelinkhub/media/amaka.jpg"    },    "content": "Good afternoon, is the flat still available for inspection this Saturday?",    "messageType": "TEXT",    "readBy": [],    "deletedAt": null,    "editedAt": null,    "replyToId": null,    "_id": "6660a7d49b1d4a0012ab3551",    "createdAt": "2026-06-05T14:02:10.107Z",    "updatedAt": "2026-06-05T14:02:10.107Z"  }}