# Send Notification

Notifies every member of the workspace with a title, a body and an optional link. Each member gets
their own copy in their notification center, and sees it on the desktop and on their phone as their
settings allow.

- Tag: `send_notification`
- Input socket: `input`
- Output socket: `output`
- `title`, `body` and `link` are text blocks that render against canonical `input`, for example
  `{{ input.status }}`.

## Who is notified, and where

- Every member of the workspace whose **Workflows** switch (Settings → Preferences → Notifications)
  is on gets one notification. A member with the switch off gets nothing.
- Every open Verdalia window of the member shows it, and it stays in their notification center
  (the bell) until they discard it, for 30 days at most.
- `phone` decides the phone:
  - `when_away` (default, **When away from Verdalia**): the member's phone is notified only when
    none of their Verdalia windows in this workspace is in use (visible, with input in the last
    two minutes).
  - `always` (**Always**): the phone is notified too, even while they are using Verdalia.

`always` never overrides a member's **Workflows** switch.

## Configuration

**title** — The notification's title (text block). Required: an empty title is a validation
finding, and a title that renders empty fails the run. The center shows it in full; the phone shows
the start of a long title.

**body** — The notification's text (text block). May be empty. The center shows it in full; the
phone and the desktop pop-up show its start.

**link** — The page opening the notification goes to (text block). One of:

- a path below the workspace: `library/weekly-report`, `/tasks`;
- the page's full address in this workspace, as agent tools return it in `url`:
  `https://verdalia.example/<workspace>/library/weekly-report`.

The query and fragment are kept. Empty after rendering means no link: opening the notification
shows it in the notification center. Anything else (another site, another workspace, a non-web
scheme, a `..` segment, nothing below the workspace, more than 1,000 bytes) fails the run, naming the rendered value, and
nothing is sent. A literal link of that kind is also a validation finding. Whether the page exists
is not checked.

**phone** — `when_away` (default) or `always`; see above.

## Inputs

**input** — Freeform payload the text blocks render against.

## Outputs

**output** — The notifications recorded, one per member notified:

```json
{
  "notifications": [
    { "id": "01JF3Z8K2W6Q0V5N7R4T1Y9XHB", "user_id": "01JD2A7M4C8P1S6V3X5Z0B9QKE" }
  ]
}
```

`notifications` is empty when no member has the **Workflows** switch on.

## Example

```json
{
  "send_notification": {
    "title": { "content": "Invoice from {{ input.sender }} is over budget" },
    "body": { "content": "{{ input.amount }} against a budget of {{ input.budget }}." },
    "link": { "content": "{{ input.document_url }}" },
    "phone": "always"
  }
}
```

```text
[Gmail Trigger] → [AI: read the invoice] → [Library: save it] → [Send Notification]
```

## Runtime Errors

| Error | Cause | Remediation |
|-------|-------|-------------|
| `title is empty, so there is nothing to notify` | The title rendered empty | Give the title text, or check the input path it reads |
| `"…" is not a page of this workspace: it is on another site` | The link names another site | Link to a page of this workspace |
| `"…" is not a page of this workspace: it is in another workspace` | The link is a page of another workspace | Link to a page of the workspace the workflow runs in |
| `"…" is not a page of this workspace: only web links of this app are allowed` | The link uses another scheme, such as `mailto:` | Use a path or the page's address |
| `"…" is not a page of this workspace: it may not contain ".."` | The link has a `..` segment | Write the path without `..` |
| `"…" does not name a page of this workspace` | Only the workspace's own address was given | Add the page's path, or leave the link empty |
| `"…" is not a page of this workspace: it is longer than 1000 bytes` | The rendered link is too long | Link to a shorter path, or leave the link empty |
| `the notification could not be stored` | The notification could not be recorded | Run the workflow again |

A phone that could not be reached does not fail the run.
