Skip to main content
Lala sends a push notification when it replies to a message, and when it writes first. Delivery is Firebase Cloud Messaging (FCM). The server addresses one device token at a time, so the client must register its token.

Register the token

Get the FCM registration token from the Firebase SDK. Then send it to the server.
Do this two times:
  1. After every sign-in.
  2. Every time FirebaseMessaging.instance.onTokenRefresh gives a new token.
The call is idempotent. A token that the server already knows updates the row. A token that belonged to another account moves to the caller. As a result, a reinstall or an account switch cannot leave the previous student reachable on this device. platform is ios or android. appVersion and locale are optional. A student with no registered token gets no notification. The chat still works.

Unregister on sign-out

Call DELETE /api/devices with the same token before you discard it.
The token is in the body, not the path. An FCM token holds characters that a path segment must escape.
The server removes a token that FCM reports as dead. You do not need to clean up after a reinstall.

Test a registration

POST /api/devices/test sends a notification to the devices of the caller. Use it to prove that a registration works.
If a device fails, results[].reason holds the message from FCM, word for word. The token in the response is masked to its last 12 characters, so two devices stay easy to tell apart. Send an empty body to reach every registered device. Send token to test one device alone.

What arrives

Every notification has the title Lala. The body is the message text, in Turkish, cut to 180 characters. The data object states the source: Route every one of these to the chat screen. They are chat messages, not system alerts.
A reply notification arrives even when the application is in the foreground. The server does not know which screen the student is on. Suppress the notification in the foreground, or the student sees an alert for a message that is already on screen.
One turn from Lala can hold more than one message bubble. The server still sends one notification. data.bubbles gives the number of bubbles, and data.messageId gives the first one.

The two proactive jobs

1

Scheduled messages, every minute

A job drains the due rows of scheduled_messages. Each row is claimed with FOR UPDATE SKIP LOCKED, so two server replicas cannot send the same message twice.
2

Silence check-in, 07:00 Europe/Istanbul

A daily job finds students who were silent for 48 hours. It writes one short message for each, and sends it one time.

The history is the source of truth

The server appends every delivered message to the conversation history with the role lala. The push is only the announcement. A push that fails to deliver does not remove the message. Call GET /api/chat/messages when the student opens the notification, and when the application returns to the foreground. Do not build the chat list from notification payloads.
Push delivery failures never break chat. The server logs a failed push and continues.

Times

Lala schedules in Turkey time (UTC+3). Timestamps in the API are UTC, ISO 8601. Convert to Europe/Istanbul for display.