---
title: "Notify people about your own events"
description: "Record an event of your own on the shared event path, turn it into a notification with setupNotifications' notify option, give it words in your messages, and deliver it in the app, by email and as push, under each person's choices."
canonical_url: "https://nuxt-backend.dev/docs/build/email/notifications/custom-events"
---
# Notify people about your own events

> Record an event of your own on the shared event path, turn it into a notification with setupNotifications' notify option, give it words in your messages, and deliver it in the app, by email and as push, under each person's choices.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- **You get:** your own events in the inbox, by email and as push, with each person's choices and the channel matrix applied.
- **Powered by:** the shared event path the activity trail records, and the package's notifications component.
- **The package adds:** the `notify` option that turns an event type into a notification, its words as translated labels, and its place on each person's profile.

Tell someone their strip was shared with them, the way the package tells them they were given a role. Your own events take the path the package's take: you record the event, and the notifications capability delivers it in the inbox, by email and as a push notification. It uses only the channels the kind allows and the person has not turned off.

## Before you start

- The event path: recording your own events on the activity trail works today ([Record your own events](https://nuxt-backend.dev/docs/build/auth/admin/audit-log#record-your-own-events)).
- The inbox in your layout ([Show the inbox](https://nuxt-backend.dev/docs/build/email/notifications#show-the-inbox)).
- `backend/notifications.ts`, and `backend/audit.ts` passing it to `setupAudit({ notifications })`: the scaffold does both, so the events you record reach `notify`.

## Record the event

Record it where it happens, about the person who should hear of it:

```ts [backend/strips.ts]
import { v } from 'convex/values'
import { audit } from './audit'
import { workspace } from './functions'

export const share = workspace.mutation({
  args: { stripId: v.id('strips'), userId: v.string() },
  handler: async (ctx, { stripId, userId }) => {
    await ctx.db.insert('stripShares', { stripId, userId })
    await audit.recordBackendEvent(ctx, {
      type: 'app.strip_shared',
      subjectId: userId,
      entityId: ctx.workspace.id,
      targetId: stripId,
    })
  },
})
```

`subjectId` names who the event is about, and so who is notified; the actor is the caller. The event lands on the activity trail and reaches your `onEvent`. On its own it becomes nothing more: you say what it becomes.

## Turn it into a notification

The `notify` option of `setupNotifications` says what each event type of yours becomes: the channels it may use and where it links:

```ts [backend/notifications.ts]
export const notifications = setupNotifications(components, {
  notify: {
    'app.strip_shared': {
      channels: ['app', 'email', 'push'],
      link: event => `/strips/${event.targetId}`,
    },
  },
})
```

A type without an entry stays a row on the trail. The channels are `app`, `email` and `push`, narrowed by the [channel matrix](https://nuxt-backend.dev/docs/build/email/notifications#the-channel-matrix) and by each person's choices. Email and push go out through `deliverNotification`, once `setupNotifications` has the email instance ([Set it up](https://nuxt-backend.dev/docs/build/email/notifications#set-it-up)). `link` returns a path of your app, read from the event as it is recorded; a link to another site is dropped, and one that throws is logged (`notifications.deliver_failed`) while the notification goes out without it. `setupNotifications` refuses a type that is not under `app.`, a channel that does not exist, and words that would replace a package kind's. Like every hook, `notify` declares when it runs and how often ([Hooks](https://nuxt-backend.dev/docs/reference/backend/hooks)).

Two rules hold for your kinds as for the package's:

- **No personal data in the event.** The row keeps ids and the few flat values you pass, for a year. The notification reads names when it is shown, so a renamed strip shows its new name.
- **The person decides.** Each kind of yours appears on the profile's email preferences with the channels it allows, and a person can turn any of them off ([Notification channels](https://nuxt-backend.dev/docs/build/email/preferences#notification-channels)).

## Send what people wait for at once

Email and push follow the weekly cap and quiet hours set on `setupEmail` ([Cap how often people hear from you](https://nuxt-backend.dev/docs/build/email/preferences#cap-how-often-people-hear-from-you)). That suits a strip shared with someone, which can wait for the morning. It does not suit news the person is waiting for: the print they ordered is ready, a job of theirs failed. Mark such a kind `transactional`:

```ts [backend/notifications.ts]
export const notifications = setupNotifications(components, {
  notify: {
    'app.strip_printed': { channels: ['app', 'email', 'push'], transactional: true },
    'app.strip_shared': { channels: ['app', 'email', 'push'], link: event => `/strips/${event.targetId}` },
  },
})
```

A transactional kind's email goes at once, as an email you send without a topic does: past the weekly cap, through the quiet hours, and without counting toward the cap. Its push goes through the quiet hours too. The person's channel choices still hold, so a person who turned its email off gets none, and an address the email provider suppressed still gets nothing. The package's own account kinds (a passkey added or removed, the address changed, a sign-in from a new device) are transactional already. Leave the option off for anything a person could read tomorrow: the cap is what keeps the rest of your email welcome.

## Give it words

A notification's words are labels, so they read in the person's language. Each kind takes a `title` and a `body` under `backend.notifications`, keyed by its type without the `app.` prefix. Placeholders fill from the event: `{actor}` is who did it, `{workspace}` the workspace it happened in, and the rest are its values (`{amount}` is an `amount` and its `currency` written as the person's currency writes them). A kind with no words reads "New activity".

```json [i18n/locales/en.json]
{
  "backend": {
    "notifications": {
      "strip_shared": { "title": "{actor} shared a strip with you", "body": "Open it to read and comment." }
    }
  }
}
```

Your messages sit beside the package's, in your i18n files or in app config ([Change copy and labels](https://nuxt-backend.dev/docs/build/ui/customize/labels)). The inbox reads either. Email and push are worded on the deployment, which reads app config's labels from `labels.generated.ts`, the file the module writes from it ([Labels reach the backend](https://nuxt-backend.dev/docs/build/ui/customize/labels#labels-reach-the-backend)), and the messages `setupEmail` takes: words in app config reach all three, and an app that translates passes its i18n files there too, English included (`messages: { en, de }`). The email channel renders the words through the `notification` template, in the package's [layout](https://nuxt-backend.dev/docs/build/email/templates/theme) with your brand, and a kind with no words there reads "New activity". Override that template to give a kind an email of its own and leave the rest as they are ([One email per notification kind](https://nuxt-backend.dev/docs/build/email/templates#one-email-per-notification-kind)).

## Forget them with what they point at

A notification links to its target for as long as it is kept, a year when unread. When you delete the target, delete its notifications in the same mutation with `notifications.forget`, so no inbox keeps a link to a page that is gone:

```ts [backend/strips.ts]
import { notifications } from './notifications'

export const remove = workspace.mutation({
  args: { stripId: v.id('strips') },
  handler: async (ctx, { stripId }) => {
    await ctx.db.delete('strips', stripId)
    await notifications.forget(ctx, { kind: 'app.strip_shared', target: stripId })
  },
})
```

`kind` is a type `notify` names, and `target` the `targetId` you recorded the events with. It deletes that kind's notifications about that target for everyone they reached, read or not, through an index, and rolls back with your mutation. The events stay on the activity trail. One call deletes up to 200 and answers `{ deleted, done }`: `done` is `false` while more are left, so a target that notified more people than that is forgotten by calling again, or from a scheduled function, until it is `true`. A kind `notify` does not name, a package kind among them, is refused with a `TypeError`.

## Check it works

Run the mutation on your dev deployment, and the notification appears live in the inbox of the person it names. The DevTools **Account** tab lists it with the channels it went out on. When the person's address is a Resend test address, the email reaches the [dev inbox](https://nuxt-backend.dev/docs/develop/dev-inbox), and a browser that subscribed on the dev app gets the push.

## Related

- [Show in-app notifications](https://nuxt-backend.dev/docs/build/email/notifications): the inbox and the channel matrix.
- [Record and review activity](https://nuxt-backend.dev/docs/build/auth/admin/audit-log): the event path, and the limits on what an event carries.
- [Feed the provider's automations](https://nuxt-backend.dev/docs/build/growth/engage/automations): the same event, sent to Resend's automations instead.
- [Send web push notifications](https://nuxt-backend.dev/docs/build/email/notifications/web-push): the push channel.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
