Skip to main content
The WebSocket API provides real-time communication for chat messages, reactions, presence tracking, and typing indicators.

Connection

Endpoint: GET /api/ws Authentication uses the session cookie set at login — no token in the URL or headers is needed. The server validates the session cookie automatically on upgrade.
Origin validation is enforced for browser clients. Non-browser clients (mobile apps, desktop, bots) that omit the Origin header are allowed through.

Connection Parameters

Client-to-Server Events

All client messages must be JSON with this structure:

ping

Client heartbeat. The server responds with a pong event.

subscribe

Subscribe to one or more channels to receive their messages and events.

unsubscribe

Unsubscribe from channels to stop receiving their events.

typing

Broadcast a typing indicator to other users in a channel. The server excludes the sender from the broadcast.

Server-to-Client Events

All server messages follow the same JSON structure:

pong

Response to a client ping event.

presence.initial

Sent immediately after connection. Contains all currently online user IDs.

presence.update

Broadcast when a user goes online or offline. Sent to all connected clients.
The status field is either "online" or "offline".

typing

Broadcast when a user is typing in a channel. Only sent to other users subscribed to that channel (the sender is excluded).

message.created

Broadcast when a new message is posted. Only sent to users subscribed to that channel.

message.updated

Broadcast when a message is edited. Only sent to users subscribed to that channel.

message.deleted

Broadcast when a message is deleted. Only sent to users subscribed to that channel.

reaction.sync

Broadcast when reactions are added or removed from a message. Contains the full reaction state for that message — not a diff.
The reaction.sync event always contains the complete reaction state for the message. Replace your local reaction state entirely rather than trying to merge it.

channel.created

Broadcast when a new channel is created. Sent to all connected clients.

channel.updated

Broadcast when a channel is renamed, moved to a different group, or reordered. Sent to all connected clients.

channel.deleted

Broadcast when a channel is deleted. Sent to all connected clients.

channel.member_added

Broadcast to a channel when members are added. Sent to all subscribers of that channel (including the newly added members).

dm.opened

Sent directly to a user when someone opens a new DM conversation with them. Not broadcast to all clients — only the recipient receives it.

Reconnection Strategy

Clients should implement automatic reconnection with exponential backoff:
  1. On disconnect, wait 1 second before the first retry
  2. Double the wait time on each failed attempt (max 30 seconds)
  3. Reset the wait time after a successful connection
  4. Re-subscribe to all channels after reconnecting
  5. Fetch missed messages via the REST API based on the last received message timestamp

Error Handling

The WebSocket connection will close with the following codes: If the connection closes abnormally (code 1006 or 1008), clients should attempt to reconnect using the strategy described above. For code 1008, verify that your token is still valid before reconnecting.