Feature: Push Notifications
Relevant source files
The following files were used as context for generating this wiki page:The notification system in the aidoit4u mobile app serves two distinct purposes. The first is a user-facing feature, allowing users to manage their preferences for receiving push notifications about updates and alerts directly on their mobile devices. This functionality is managed via the app's settings screen and is powered by the expo-notifications library.
The second is a backend service designed to send notifications to the project owner. This internal system, implemented in server/_core/notification.ts, dispatches alerts through the Manus Notification Service and is not directly exposed to the end-user. This document covers the architecture and implementation details for both aspects of the notification system.
System Architecture
The notification architecture is split into two main flows: the client-side user notifications and the server-side owner notifications.
User-Facing Push Notification Flow (Client-Side)
This diagram illustrates the conceptual flow for user-facing push notifications, which are managed from the app's settings screen.
Owner Notification Flow (Server-Side)
This sequence diagram shows the process of the backend sending a notification to the project owner using the notifyOwner function.
Sources: server/_core/notification.ts
Client-Side Implementation
The client-side implementation provides the user interface for managing notification preferences. The project plan and design documents specify a "Notification preferences" section within the Settings screen.
Sources: design.md:95, todo.md:49
Dependencies
The core technology for handling push notifications on the client is the expo-notifications package.
Sources: package.json:41
UI and Localization
The settings screen includes options for enabling or disabling push notifications. The text for these options is localized in English, Spanish, and German.
| Key | English | Spanish | German |
|---|---|---|---|
notifications | Notifications | Notificaciones | Benachrichtigungen |
pushNotifications | Push Notifications | Notificaciones Push | Push-Benachrichtigungen |
receiveUpdates | Receive updates and alerts | Recibe actualizaciones y alertas | Erhalte Updates und Benachrichtigungen |
Sources: lib/translations.ts:130-132, 256-258, 383-385
Backend Service: Owner Notifications
The backend provides a dedicated function, notifyOwner, to send notifications to the project owner via the Manus Notification Service. This is an internal mechanism and is not intended for sending push notifications to app users.
Sources: server/_core/notification.ts
notifyOwner Function
The notifyOwner function is an async function that takes a NotificationPayload object and returns a Promise<boolean>. It returns true if the notification was successfully dispatched and false if the service could not be reached.
Sources: server/_core/notification.ts:60-99
API and Payload
The function sends a POST request to a specific endpoint derived from the forgeApiUrl environment variable.
- Endpoint Path:
webdevtoken.v1.WebDevService/SendNotification
Sources: server/_core/notification.ts:11-14
The body of the request contains a NotificationPayload object with the following structure:
| Field | Type | Description | Constraints |
|---|---|---|---|
title | string | The title of the notification. | Required, non-empty, max 1200 characters. |
content | string | The main body/content of the notification. | Required, non-empty, max 20000 characters. |
Sources: server/_core/notification.ts:4-7, 16-43
Payload Validation
Before sending the request, the validatePayload function is called to ensure the payload meets the required criteria. It performs the following checks:
- Ensures
titleandcontentare non-empty strings. - Trims leading/trailing whitespace from
titleandcontent. - Validates that
titledoes not exceed 1200 characters. - Validates that
contentdoes not exceed 20000 characters.
If any validation fails, a TRPCError with a BAD_REQUEST code is thrown.
Sources: server/_core/notification.ts:16-43
Configuration
The notifyOwner function relies on two environment variables to connect to the Manus Notification Service. If these are not configured, a TRPCError with an INTERNAL_SERVER_ERROR code will be thrown.
| Variable | Description |
|---|---|
ENV.forgeApiUrl | The base URL for the Manus Notification Service. |
ENV.forgeApiKey | The bearer token for authenticating with the service. |
Sources: server/_core/notification.ts:62-71