# Notifications

The built-in user notifications system lets the backend notify a user of something new. This could be a simple message and/or a JSON data blob.

The notifications database table is responsible for storing all notifications and recording whether they have seen by the user or not.

Note that notifications can only be created from within the backend (including background workers).

# Creating a notification

The backend bootstrap object provides a convenient API for creating notifications:

/**
 * @id User id in database table.
 * @data Notification data.
 */
async function notifyUser (id: User, data: object): Promise<void>

This does two things:

  1. Creates the corresponding entry in the notifications table.
  2. Sends a push notification to the user informing them of new notifications. (The frontend automatically updates the notifications indicator in the browser UI).

The data parameter can contain any structure, though at present the following structure is handled in the UI by default:

{
  msg: "The notification message to show",
}