Authentication
All User Presence Status API methods require authentication via theAuthMiddleware. Include a valid bearer token in your requests.
Status Types
The API supports the following presence statuses:online- User is active and availableaway- User is inactive or temporarily unavailablebusy- User is active but should not be disturbeddnd- Do Not Disturb mode (suppresses notifications)offline- User is not available
Methods
Update Presence Status
Update the user’s presence status and optional custom message. The userId is automatically set from the authenticated user.User’s presence status. If not provided, defaults to existing status or “online”
Custom status message to display (e.g., “In a meeting”, “On vacation”). Set to null to clear.
Emoji to display with the status (e.g., ”📅”, ”🌴”). Set to null to clear.
When the custom status should automatically clear. Set to null for no expiration.
ID of the channel the user is currently viewing/active in. Set to null to clear.
Whether to suppress notifications while this status is active
The updated presence status object
Transaction ID for optimistic updates
UnauthorizedError- User is not authenticatedInternalServerError- Unexpected server error
- All parameters are optional and merge with existing values
- If no status record exists, one is created with default values
- Updates the
lastSeenAttimestamp as a heartbeat - Performed within a database transaction
Heartbeat
Lightweight heartbeat to update the lastSeenAt timestamp. Used for reliable offline detection - if no heartbeat is received within the timeout period, the user is marked offline by a server-side cron job.Empty object (no parameters)
Updated timestamp of when the user was last seen active
UnauthorizedError- User is not authenticatedInternalServerError- Unexpected server error
- If no presence status record exists, creates one with “online” status
- Only updates the
lastSeenAtfield, no other status changes - Very lightweight operation designed for frequent polling
- Typical usage: Send heartbeat every 30-60 seconds from active clients
Clear Custom Status
Clears the user’s custom status (emoji, message, and expiration). Does not affect the user’s presence status (online/away/etc).Empty object (no parameters)
The updated presence status object with cleared custom status fields
Transaction ID for optimistic updates
UnauthorizedError- User is not authenticatedInternalServerError- Unexpected server error
- Clears
customMessage,statusEmoji, andstatusExpiresAt - Preserves the
statusfield (online/away/busy/dnd/offline) - Preserves the
activeChannelIdfield - Resets
suppressNotificationsto false - Updates the
lastSeenAttimestamp
Usage Patterns
Offline Detection
Hazel Chat uses a heartbeat-based system for reliable offline detection:- Client sends heartbeats: Active clients should call
heartbeat()every 30-60 seconds - Server tracks lastSeenAt: Each heartbeat updates the
lastSeenAttimestamp - Server-side cron job: A background job periodically checks for stale
lastSeenAttimestamps - Automatic offline marking: Users with no recent heartbeat are automatically marked as offline
Error Handling
Related APIs
- Users API - Manage user accounts and profiles
- Notifications API - Status affects notification delivery