net_backend

API reference

Chat flows

Public room, live:

  1. GET /v1/chat/rooms (HTTP) to show the public rooms (key, name, member_count).
  2. Open the WebSocket and authenticate (auth → auth.ok).
  3. chat.join {"room":"world"} → RoomInfo (keep its id).
  4. chat.history {"room":12,"limit":50} → the latest messages (newest first: reverse for display).
  5. chat.send {"room":12,"text":"hello","nonce":"k3j9x"} → {"message_id":981,"sent_at":…}; then your own chat.message push with id: 981 arrives.
  6. Show every chat.message push for the room; remove messages on chat.deleted; update the online list on chat.presence (or ask chat.members).
  7. After a reconnect: chat.join again, then load history newer than the last message you have (page with chat.history until you reach a known id).

Direct messages:

  1. POST /v1/chat/dm {"user":77} → RoomInfo with kind: "dm", peer: 77 (the same room every time for the same pair).
  2. chat.send {"room":<dm room id>,"text":"…"}: no join needed; both players receive chat.message on every open connection.
  3. GET /v1/chat/dms lists the caller's DM rooms, newest activity first; history works as for any room.

Older history: pass the previous page's next_cursor as cursor (HTTP query or WebSocket data) until next_cursor is absent. Messages are kept 30 days by default.

Moderation: DELETE /v1/chat/rooms/{room}/messages/{message} by the sender or a moderator; the room gets chat.deleted. Editing: chat.edit (or PATCH on the same path) by the sender within the edit window, or a moderator; the room gets chat.edited.

Unread counts and "seen":

  1. On opening a room, take the newest message's id and send chat.mark_read {"room":12,"message":<id>} (once per batch of messages, not for every message).
  2. For badges, chat.unread {"rooms":[12,13,…]} with the rooms on screen; after a reconnect ask again.
  3. In DM, group and player rooms show the other members' markers from chat.read pushes; chat.receipts {"room":12} gives the current ones (for example after a reconnect).

Typing: while the player types, chat.set_typing {"room":12,"typing":true} about every 3 s; {"typing":false} when they stop or clear the input. Show others' chat.typing until expires_in_ms passes or their message arrives.

A player's own room:

  1. POST /v1/chat/rooms {"name":"Night Owls","visibility":"private"} → RoomInfo (role: "owner").
  2. POST /v1/chat/rooms/{room}/invites {"user":77}: the player gets chat.room invited (and a chat.invite notification with the notifications module); GET /v1/chat/rooms/mine lists it with role: "invited".
  3. The invited player joins with chat.join {"room":<id>} (or POST /v1/chat/rooms/{room}/join) and chats as in any room; POST …/leave declines or leaves.
  4. The owner: PUT …/members/{user}/role {"role":"moderator"}, DELETE …/members/{user} (a kick: banned until invited again), PATCH … to rename or open it, POST …/owner to hand it on, DELETE … to delete it.

Do not resend chat.send automatically after a reconnect: it could post a message twice. If the answer was lost, look for your nonce in the history first.

Generated from API.md (repository commit 84a9d3c, file sha256 e735542eb5f5).