Leave Localhost logoLeave LocalhostDocs
Recipes

Add a Notification Type

Register a new in-app notification event and emit it from a product flow, with optional email-delivery defaults.

Add a new notification event and emit it from a backend flow. See Notifications for what the system does and does not do (it is an in-app system, not a campaign/push product).

1. Register the event type

Add the new event to the notification validators/types in packages/backend/convex/notifications/ and give it a default delivery preference. The catalog of events is documented at Notification Events.

2. Emit it from your flow

When the triggering change happens, insert a notification row in the same mutation, using the internal notification helper rather than writing the table directly:

await createNotification(ctx, {
  recipientUserId: member.appUserId,
  event: "report.shared",
  title: "A report was shared with you",
  body: `${actorName} shared "${report.title}"`,
  link: `/reports/${report._id}`,   // optional deep link
  organizationId: actor.organizationId,
});

Because Convex queries are realtime, the recipient's bell and unread count update automatically — there is no socket to wire.

3. Respect preferences

The helper honors notification_preferences. Expose a toggle for the new event in the notifications settings screen if users should control it — see Notification Preferences.

4. Email delivery (optional)

The starter does not send notification emails automatically. To add delivery, follow Email Notifications: create the row first, then schedule provider delivery and patch emailDelivery.

On this page