---
title: "Notifications and Live Updates"
manual: "adsum by web-vision"
version: "main"
permalink: "https://docs.typo3.org/permalink/web-vision/adsum-monorepo:extending-events-notifications@main"
source: "Extending/EventsAndNotifications.rst"
rendered: "2026-11-07T02:01:32+00:00"
---

# Notifications and Live Updates {#extending-events-notifications}

A package tells people what its messages report: in the notification centre, by e-mail and as a live update in open
pages. The messages are listed in [Events and Messages](https://docs.typo3.org/permalink/web-vision/adsum-monorepo:extending-events-messages@main).

## Notification types {#notification-types}

A notification type implements `NotificationType` and names the messages that trigger it. This type of the
attendance package informs HR about work on an absence day:

```php
/**
 * @implements NotificationType<WorkOnAbsenceDetected>
 */
final readonly class WorkOnAbsenceNotification implements NotificationType
{
    public function __construct(
        private Recipients $recipients,
    ) {}

    public static function definition(): NotificationTypeDefinition
    {
        return new NotificationTypeDefinition(
            'time.workOnAbsence',
            'time',
            [WorkOnAbsenceDetected::class],
            'HR',
            new ChannelChoice(true, true),
        );
    }

    public function notices(object $event): array
    {
        $companyId = CompanyId::fromString($event->companyId);
        $parameters = ['employeeName' => $this->recipients->displayName($event->employeeId) ?? '', 'date' => $event->date->format('Y-m-d')];

        return \array_map(
            static fn(string $userId): Notice => new Notice($userId, $companyId, $parameters, new NotificationSubject('attendanceDay', $event->dayId)),
            $this->recipients->holders($companyId, Role::Hr),
        );
    }
}
```

The constructor of `NotificationTypeDefinition` takes:

-   **`key`**

    A unique key, such as `time.workOnAbsence`.

-   **`category`**

    A group of types, such as `time`. The category `security` (constant `CATEGORY_SECURITY`) marks types that a
    user cannot switch off.

-   **`events`**

    The messages that trigger the type.

-   **`recipients`**

    A description of the recipients in words, for the catalogue of types.

-   **`defaults`**

    A `ChannelChoice` with the default for the channels in-app and e-mail.

-   **`channels`**

    The supported channels, `['inApp', 'email']` by default.

-   **`supportsDigest`**

    Whether the e-mails of the type can be summarised in the daily digest.

`notices()` receives the message and returns a `Notice` per recipient: user ID, company, parameters and
optionally the subject the notification is about. A notice must not contain more than the recipient may read through
the API. Users choose per type whether they get it in-app and by e-mail.

### Texts of a notification {#texts-of-a-notification}

Title and body are translations with the keys `notification.type.<key>.title` and
`notification.type.<key>.body`; the parameters of the notice are the placeholders (see
[Translations and Icons](https://docs.typo3.org/permalink/web-vision/adsum-monorepo:extending-translations-icons@main)). A parameter whose name ends in `Text` holds a translation key, such as
`ruleText: 'screen.violation.rule.dailyAverageExceeded'`, shown in the reader's language from any installed package
that has it, or as the last part of the key:

```xml
<unit id="notification.type.time.workOnAbsence.body" name="notification.type.time.workOnAbsence.body">
  <segment>
    <source>notification.type.time.workOnAbsence.body</source>
    <target>{employeeName} worked on {date}, a day of approved absence.</target>
  </segment>
</unit>
```

### Links, channels and digest {#links-channels-and-digest}

A `NotificationLink` turns a `NotificationSubject` (type and ID) into a page:

```php
final readonly class AttendanceDayLink implements NotificationLink
{
    public function subjectType(): string
    {
        return 'attendanceDay';
    }

    public function path(string $subjectId): string
    {
        return '/attendance-days/' . $subjectId;
    }
}
```

A `NotificationChannel` adds a delivery channel next to `inApp` and `email`. A `DigestSection` adds a line to
the daily digest.

## Live updates {#live-updates}

Open pages receive live updates through Mercure. A package declares a topic with `RealtimeTopic`; an unregistered
topic is never granted. This is the topic of a user's approval inbox:

```php
final readonly class UserApprovalsTopic implements RealtimeTopic
{
    public function template(): string
    {
        return '/users/{userId}/approvals';
    }

    public function access(): array
    {
        return ['self', 'approver'];
    }

    public function grants(User $user, CompanyId $companyId, array $parameters): bool
    {
        return ($parameters['userId'] ?? null) === $user->getUserIdentifier();
    }
}
```

`template()` is the topic path with `{name}` placeholders. `access()` lists the actors that may subscribe, as in
`#[Access]` (see [Navigation and Access](https://docs.typo3.org/permalink/web-vision/adsum-monorepo:extending-navigation-access@main)). `grants()` decides for one user with the API's rules.

A listener queues an update with `RealtimeUpdates`. The payload holds the kind, IDs and a short summary, never more
than the API shows:

```php
$this->updates->queue('/users/' . $userId . '/approvals', ['kind' => 'approval.withdrawn', 'approvalId' => $id]);
```

The update is sent after the command's transaction is committed; a rolled-back command sends nothing.
