Listoca

Notifications

The in-app inbox, emails one by one or as a daily summary, and push to the user's devices (the push part).

A notification is one row in notifications for one recipient. Server-side code creates it, and the deliver-notifications function decides where it goes: the inbox in the app, an email now or in the daily summary, and a push to the devices where the user turned push on. The inbox syncs to the devices, so it opens offline.

Sending one

From SQL (a trigger, an RPC) or an Edge Function with the service role:

select public.notify(user_id, 'message', '{"message": "Your export is ready."}');
await deps.admin.rpc("notify", {
  recipient: userId,
  notification_type: "billingIssue",
});

Clients can't create notifications. Admins send a "message" from the user's page in the web admin area (admin_send_message).

Types

Each type is an entry in packages/notifications/src/registry.ts: the channels it offers with their defaults, a zod schema for its data, the screen it leads to (an app page) and whether it is urgent. Its text is notifications.<type>.title, .body, .label and .description in the i18n shared scope; the data are the ICU arguments.

TypeChannels (default)Leads to
messagein the app (on), email (off), push (on)the inbox
billingIssuein the app (on), email (on), urgentthe plan screen

billingIssue comes with the payments part: the RevenueCat webhook sends it on a BILLING_ISSUE event.

Delivery

  1. notify() inserts the row. A trigger calls deliver-notifications right away; pg_cron calls it every minute for anything that was missed.
  2. The function reads the recipient's choices from their profile (notification_preferences, email_frequency) and applies deliveryFor:
    • in the app: the row gets in_app = true, and the notifications stream brings it to their devices.
    • email now: a row in email_outbox with the notification template, sent by send-queued-email. The link goes through the marketing site's /open/…, which opens the app on a phone that has it.
    • daily summary: the row waits (summary_pending); send-digests sends one email per user at 8:00 in their time zone. Urgent types always go out right away.
    • push: one message per registered device through Expo's push service. Tapping it opens the screen.
  3. When Expo's push service is down, nothing is marked and the next run tries again (up to five attempts). check-push-receipts removes tokens of devices that are gone.

Notifications older than 90 days are deleted.

Settings

The user chooses per type and channel, and between single emails and the daily summary, in the app (Settings → Notifications) or on the web account page. Both write the same two profile columns, so the choice syncs and works offline.

Push

Push needs an EAS project: run eas init in apps/native, which writes extra.eas.projectId into app.json, and set up the push credentials (APNs key, FCM) in the Expo dashboard. Without a project id the app shows "Push isn't set up for this build yet."

The app asks for permission only when the user turns push on in the notification settings, never at launch. The token is registered with register_push_token and removed on sign-out.

In production set the function's env:

PUSH_PROVIDER=expo
# only once enhanced push security is on in the Expo dashboard
EXPO_ACCESS_TOKEN=...

Locally PUSH_PROVIDER=console logs pushes instead of sending them.

Adding a type

The add-a-notification skill has the steps: the registry entry, the text in every locale, the notify() call and a test.

On this page