# Watchlist, alerts and notifications

Webhooks and the stream carry **every** signal in your package to software. Alerts are for **people**: they follow
companies, say which new signals of those companies matter to them, and get an inbox item, an email or a push
notification.

<Figure name="alert-fanout" caption="A released ACTION or WATCH signal goes to every account that follows the company and has a matching rule: one inbox item each, then email and push as the account chose." />

These routes take a session or the live key (named keys and the sandbox key are refused). Watchlist, rules and push
devices need paid access (402 otherwise); the inbox and notification settings stay open without it, so an app can
still show subscription notices.

## Watchlist

| Route | Does |
| --- | --- |
| `GET /api/v1/customer/follows` | The followed companies: `{ items: [{ issuerId, ticker, name, followedAt, alerting }], total, limit }` |
| `PUT /api/v1/customer/follows/{issuerId}` | Follow (201, or 200 if already followed) |
| `DELETE /api/v1/customer/follows/{issuerId}` | Unfollow; rules that name only this company go too (`removedRules`) |

`alerting` says whether a rule covers the company. An account may follow 25 (`signal`), 100 (`desk`) or 500 (`firm`)
companies by default; past that, `409 follow_limit`. An unknown company is 404.

## Alert rules

A rule says which new signals notify, and on which channels besides the inbox:

```bash
curl -sS -X POST "$RISKPILOT_URL/api/v1/customer/alerts" \
  -H "Authorization: Bearer $RISKPILOT_SESSION" -H "Content-Type: application/json" \
  -d '{ "classes": ["ACTION"], "families": ["8-K", "425"], "issuerId": null, "email": true, "push": true }'
```

A rule for any company in a sector, with an impact threshold, keywords, quiet hours, a daily cap and a Slack channel:

```bash
curl -sS -X POST "$RISKPILOT_URL/api/v1/customer/alerts" \
  -H "Authorization: Bearer $RISKPILOT_SESSION" -H "Content-Type: application/json" \
  -d '{ "name": "Biotech catalysts", "scope": "any", "sectors": ["Health Care"], "industries": ["2834"],
        "classes": ["ACTION", "WATCH"], "minImpact": 4, "direction": "any",
        "keywords": ["FDA", "\"definitive agreement\"", "-offering"],
        "quietHours": { "start": "22:00", "end": "07:00", "tz": "America/New_York" },
        "dailyCap": 5, "email": false, "push": false, "channelIds": ["12"] }'
```

| Field | Meaning |
| --- | --- |
| `classes` | `ACTION` and/or `WATCH`, as far as your package shows them (`GET /alerts` returns the allowed `classes`); otherwise `400 class_not_in_package`. DROP never alerts |
| `families` | Form families; empty or missing: every family |
| `issuerId` | One followed company, or `null` for every followed company (`400 not_followed` for a company you do not follow). Must be `null` with `scope: "any"` |
| `name` | Optional label, up to 80 characters |
| `scope` | `watchlist` (default): only companies you follow. `any`: every company in your package, narrowed by `sectors` and `industries` |
| `sectors` | Sector names, matched exactly (any case); empty: every sector |
| `industries` | SIC code prefixes (`"28"`, `"2834"`) or words of the SIC description (`"semiconductor"`); empty: every industry |
| `minImpact` | 1–5: the signal's impact must be at least this (`null`: no threshold). Impact is the payload's `impact`; where an older item has none it is derived from class and score the same way (DROP 1, WATCH 2–3, ACTION 3–5) |
| `direction` | `any` (default), `up` or `down`. A signal without a known direction matches only `any` |
| `keywords` | Up to 20 terms matched as whole words, any case, in the headline and summary. `"quoted phrase"` matches the phrase; a leading `-` excludes (`-offering`). With include terms, at least one must match; any exclude term blocks |
| `quietHours` | `{ "start": "HH:MM", "end": "HH:MM", "tz": "America/New_York" }`, `null` for none. Start inclusive, end exclusive, wraps past midnight; `tz` an IANA zone (`null`: UTC). During quiet hours a match reaches the inbox only, not email, push or chat |
| `dailyCap` | 1–10000 alerts of this rule per day (in the rule's `tz`, else UTC); past it the rule stops matching until the next day. `null`: no cap |
| `email`, `push` | Channels besides the inbox (default email on, push off) |
| `channelIds` | Up to 10 of your chat channels (below) that also receive the alert; `400 channel_not_found` for one that is not yours |
| `enabled` | Switch the rule off without deleting it |

List fields take at most 20 entries of 80 characters each. `GET /customer/alerts` lists the rules and returns the
package's `limit` and `alertsPerDay`; `PATCH /customer/alerts/{id}` changes any field, `DELETE` removes one.
Following a company without a rule only lists it.

| Package | Rules (`409 rule_limit` past it) | Alerts per day that leave the inbox |
| --- | --- | --- |
| `signal` | 10 | 50 |
| `desk` | 25 | 250 |
| `firm` | 100 | 2000 |

Past the daily alert cap (counted from UTC midnight) alerts still land in the inbox; email waits for the daily digest,
and push and chat are skipped until the next day.

How a new signal is matched: when a signal is released, RiskPilot finds the accounts with an enabled rule that may
cover it (watchlist rules of the company's followers and `any` rules), and reads the signal through each account's own
scope, so a signal your package may not see never alerts. Then every filter of each rule applies: class, family,
company, sector, industry, impact, direction and keywords, then the rule's daily cap. Paused accounts and accounts
without paid access get nothing. Each account gets one inbox item per filing, however many rules match; email, push
and chat go out when at least one matching rule is outside its quiet hours, to the union of their channels.

## Chat channels: Discord, Slack and Telegram

Alerts can also go to a Discord or Slack channel (incoming webhook) or a Telegram chat. Each service is off unless the
server switches it on (`RP_NOTIFY_DISCORD`, `RP_NOTIFY_SLACK`, `RP_NOTIFY_TELEGRAM`); the settings answer's `chat`
object, and `available` in the list answer, say which are on. Creating one that is off answers `503 channel_unavailable`.

| Route | Does |
| --- | --- |
| `GET /api/v1/customer/channels` | `{ items: [channel], available: { discord, slack, telegram } }` |
| `POST /api/v1/customer/channels` | Add one: `{ "kind": "discord" \| "slack", "url": "…", "label": "#alerts" }` or `{ "kind": "telegram", "label": "My phone" }` (201) |
| `POST /api/v1/customer/channels/{id}/verify` | Discord/Slack: send a test and mark the channel verified if it goes through. Telegram: check whether the chat has linked |
| `POST /api/v1/customer/channels/{id}/relink` | Telegram: a fresh link code (the old one stops working) |
| `POST /api/v1/customer/channels/{id}/test` | Send a test message now: `{ ok, status, error }` (5 per hour) |
| `DELETE /api/v1/customer/channels/{id}` | Remove it; rules stop naming it and queued messages are dropped |

A channel answer never contains the webhook URL: `target` is masked to the host, path and last four characters of the token (`hooks.slack.com/services/T0A1/B0C2/…x9Qz`), or
`"linked chat"` for Telegram. Only **verified** channels receive alerts. An account keeps at most 10 channels
(`409 channel_limit`), and each channel gets at most 30 alerts an hour (the rest stay in the inbox).

- **Discord:** in the server, Settings → Integrations → Webhooks → New Webhook → Copy Webhook URL. Only
  `https://discord.com/api/webhooks/{id}/{token}` (or `discordapp.com`) is accepted, optionally with `?thread_id=`.
- **Slack:** create an app with Incoming Webhooks and add one to a channel. Only `https://hooks.slack.com/services/…`
  is accepted.

Any other host, `http`, a port, or a path of another shape is refused with `400 url_not_allowed`; credentials in the
URL or an address that resolves to a private network are refused by the same guard as outgoing webhooks (400). Adding a Discord or Slack channel sends a "connected" message at once and the answer's
`test` says whether it went through; a channel whose message failed stays unverified until `verify` succeeds.

**Telegram** works through the RiskPilot bot. Adding a channel returns a link:

```json
{
  "channel": { "id": "14", "kind": "telegram", "label": "My phone", "target": null, "verified": false, "linkPending": true },
  "link": { "code": "rpQ8K2M4X7A1BC", "url": "https://t.me/RiskPilotBot?start=rpQ8K2M4X7A1BC", "botName": "RiskPilotBot",
            "expiresAt": "2026-12-02T10:30:00.000Z", "mode": "webhook" },
  "test": null
}
```

Open `url` and press Start. If the deep link does not open (desktop without the app, or a group), send
`/start rpQ8K2M4X7A1BC` to the bot yourself; in a group, add the bot first and send the command there. The code works
for 30 minutes and once; `relink` gives a new one. With `mode: "webhook"` the channel turns verified a moment later on
its own; with `mode: "check"` call `verify` (the portal's Check button) after sending the code. The bot confirms in
the chat.

Every chat message carries the ticker, form, class, impact dots (`●●●●○`), direction, a one-line summary and the SEC
link, for example `ACME · 8-K · ACTION · ●●●●● · ▲ up`. Failed sends retry with the same backoff as email and push; a
webhook that answers 401, 403, 404 or 410 (deleted), or a Telegram chat that blocked the bot, disables the channel.

### Server configuration

| Variable | Meaning |
| --- | --- |
| `RP_NOTIFY_DISCORD`, `RP_NOTIFY_SLACK`, `RP_NOTIFY_TELEGRAM` | `1` switches the service on (default off) |
| `RP_TELEGRAM_BOT_TOKEN` | The bot token from BotFather; Telegram stays off without a valid one |
| `RP_TELEGRAM_BOT_USERNAME` | The bot's username for the deep link (otherwise asked from Telegram) |
| `RP_TELEGRAM_WEBHOOK_SECRET` | When set, register `https://<api>/api/v1/telegram/webhook` with `setWebhook` and this `secret_token`; links then complete on their own. Without it the Check button polls `getUpdates` |
| `RP_NOTIFY_CHAT_PER_HOUR` | Alerts per chat channel per hour (default 30) |
| `RP_NOTIFY_CHAT_CHANNEL_LIMIT` | Chat channels per account (default 10) |
| `RP_ALERT_RULE_LIMITS`, `RP_ALERTS_PER_DAY` | Per-package overrides, e.g. `signal=10,desk=25,firm=100` |

## Inbox

| Route | Does |
| --- | --- |
| `GET /api/v1/customer/notifications?unread=true&before=<id>&limit=30` | Newest first: `{ items, nextBefore, unread }` |
| `GET /api/v1/customer/notifications/unread-count` | `{ unread }`, for a badge |
| `POST /api/v1/customer/notifications/read` | `{ "ids": ["…"] }` or `{ "all": true }`; add `"read": false` to mark unread |

The inbox pages by cursor: pass the answer's `nextBefore` as `before` for the next page (`null` at the end). An item:

```json
{
  "id": "5512",
  "kind": "alert",
  "type": "signal.alert",
  "title": "ACTION · ACME · 8-K",
  "body": "Acme agrees to be acquired for $42 per share in cash",
  "link": "/c/signals/0001437749-26-031545",
  "filingId": "0001437749-26-031545",
  "issuerId": "0000123456",
  "data": { "className": "ACTION", "family": "8-K", "ticker": "ACME", "score": 87 },
  "createdAt": "2026-11-10T16:00:01.000Z",
  "readAt": null
}
```

`kind` is `alert` or `system`. System items are subscription notices: `billing.started`, `billing.renewed`,
`billing.payment_failed`, `billing.expiring` (`data.reason`: `canceled` or `grace`) and `billing.expired`, all linking
to `/c/billing`. Without paid access an account sees only system items. `link` is a path in the customer portal.

## Email and push settings

`GET /api/v1/customer/notifications/settings` returns the account's choices and what the server offers:

```json
{
  "preferences": { "emailAlerts": "instant", "emailSystem": true, "pushAlerts": true },
  "email": { "enabled": true, "address": "ops@acme.example", "verified": true },
  "push": { "webpush": { "enabled": true, "publicKey": "BM…" }, "fcm": { "enabled": false }, "apns": { "enabled": false } },
  "chat": { "discord": true, "slack": true, "telegram": false }
}
```

`PATCH` the same route with any of `emailAlerts` (`instant`, `digest`, `off`), `emailSystem` and `pushAlerts`.

- **Email** goes only to a confirmed address. Instant alert mail is capped at 20 per account per hour; past that,
  alerts wait for the daily digest (one mail a day listing up to 25 alerts). Every mail has a one-click opt-out link;
  `POST /customer/notifications/unsubscribe` with its `token` switches alert mails off (and with `"all": true` the
  subscription notices too) without signing in.
- **Push** goes to every registered device of the account, at most 30 alerts per device per hour (the rest stay in the
  inbox). The inbox always gets every alert, whatever the email and push settings.

## Registering a push device

| Platform | Body of `POST /api/v1/customer/push/devices` |
| --- | --- |
| Browser (Web Push) | `{ "provider": "webpush", "endpoint": "https://…", "keys": { "p256dh": "…", "auth": "…" }, "label": "Chrome on laptop" }`: the browser's `PushSubscription.toJSON()`, subscribed with `push.webpush.publicKey` |
| Android (FCM) | `{ "provider": "fcm", "token": "<FCM registration token>", "label": "Pixel 9" }` |
| iOS (APNs) | `{ "provider": "apns", "token": "<APNs device token>", "label": "iPhone" }` |

The answer is `201` with the device. Registering a device that another account registered moves it to you, so a
shared phone never gets the previous account's alerts. An account keeps at most 10 devices (the least recently seen
goes). `GET /customer/push/devices` lists them, `DELETE /customer/push/devices/{id}` removes one, and
`POST /customer/push/test` sends a test push to every device (5 per hour; `409 no_device` without one).

A Web Push message is the JSON `{ "title", "body", "url", "tag" }`, which your service worker shows.

:::note{title="Mobile push is not switched on yet"}

The FCM and APNs channels exist in the API but their senders are not implemented yet: with them off (the default) a
registration answers `503 push_unavailable`, and `push.fcm.enabled` / `push.apns.enabled` are `false`. Build your
app's registration against these routes now and check those flags at start-up; alerts reach the inbox in the
meantime. See [Mobile apps](/mobile).

:::
