GET /api/chat/stream is a long-lived text/event-stream. It carries everything that reaches the
conversation without a request from this device:
- Scheduled messages that Lala planned earlier.
- The daily check-in after a silence.
- Messages and reactions from the student’s other devices.
Events
StreamMessageEvent
A message reached the conversation.
StreamReactionEvent
The reactions on this message changed. The payload is the whole message.
object
A keep-alive, about every 25 seconds. Ignore the payload.
message payload is a full ChatMessage, in the same shape as
the history. It needs no extra fetch.
Rules for the client
- Merge each
messageinto the local list byid. - The stream repeats messages this device produced through
POST /api/chat/send. De-duplicate byid. Do not render the same message twice. - On
reaction, replace the reactions of that message. - If no
pingarrives for 60 seconds, treat the stream as dead and reconnect. - After a reconnect, read
GET /api/chat/messages?after=<cursor of your newest message>to fill the gap.
Push and the stream
Push notifications and this stream cover different states. Push reaches a closed application. The stream reaches an open one. The server does both for every proactive message, so an open application can receive a push it does not need. Read Push notifications.Delivery
The stream is best effort. A message always reaches the database first, and the stream announces it after. A dropped event costs you the live update, not the message. Theafter parameter
recovers it.