Overview
Messages are the core content of conversations in Hazel Chat. Each message belongs to a channel and has an author. Messages support:- Plain text content
- Rich embeds for links and media
- Attachments (images, files)
- Replies to other messages
- Thread creation
Authentication
All message operations require authentication viaAuthMiddleware. The authorId is automatically set from the authenticated user context.
Rate Limiting
Message operations are rate-limited to 60 requests per minute per user to prevent spam and abuse.Methods
message.create
Creates a new message in a channel.The ID of the channel to post the message in
The text content of the message
Rich embed data for links, images, or other media
ID of the message this is replying to
ID of the thread channel if this message creates or belongs to a thread
Array of attachment IDs to link to this message. Attachments must be uploaded first.
Response
The created message object
Transaction ID for optimistic UI updates
Errors
ChannelNotFoundError- The specified channel does not existUnauthorizedError- User lacks permission to post in this channelRateLimitExceededError- User has exceeded the rate limit (60/min)InternalServerError- An unexpected error occurred
Example
message.update
Updates an existing message. Only the message author or users with appropriate permissions can update messages.Only
content and embeds can be updated. Immutable fields like channelId, replyToMessageId, and threadChannelId cannot be changed to prevent moving messages between channels or fabricating conversation context.The ID of the message to update
New text content for the message
Updated embed data
Response
The updated message object (see message.create for fields)
Transaction ID for optimistic UI updates
Errors
MessageNotFoundError- The specified message does not existUnauthorizedError- User lacks permission to update this messageRateLimitExceededError- User has exceeded the rate limit (60/min)InternalServerError- An unexpected error occurred
Example
message.delete
Deletes a message (soft delete). Only the message author or users with appropriate permissions can delete messages.This is a soft delete operation. The message is marked as deleted but remains in the database with a
deletedAt timestamp.The ID of the message to delete
Response
Transaction ID for optimistic UI updates
Errors
MessageNotFoundError- The specified message does not existUnauthorizedError- User lacks permission to delete this messageRateLimitExceededError- User has exceeded the rate limit (60/min)InternalServerError- An unexpected error occurred
Example
Best Practices
Optimistic Updates
Use thetransactionId returned from all operations to implement optimistic UI updates:
Rate Limiting
Handle rate limit errors gracefully:Attachment Handling
Always upload attachments before creating the message:Source Code Reference
- RPC Contracts:
packages/domain/src/rpc/messages.ts - Message Model:
packages/domain/src/models/message-model.ts - Backend Handlers:
apps/backend/src/rpc/handlers/messages.ts - Message Policy:
apps/backend/src/policies/message-policy.ts