# Alert

A line of text to a team's chat: Slack's and Discord's incoming webhooks,
or any address that takes a JSON post; and, if asked, every fault of the
back end, the same one once in ten minutes. An
[extension](../extensions/README.md): `extensions/alert/`. (It is not
`notify`, the runtime's own [notifications](back-end.md#notifications) to a
person's devices.) Back to the [map](README.md).

```mote
use "pkg:alert/alert.mote"

server after Order.add(o)
  if o.total > 100000 alertSend(`A big order: ${o.id}`, "info")
```

```sh
ALERT_SLACK=https://hooks.slack.com/services/… ALERT_DISCORD=https://discord.com/api/webhooks/… ALERT_FAULTS=on bun dist/server/main.js
```

| Setting | |
|---|---|
| `ALERT_SLACK` | A Slack incoming webhook: posted `{text, username}`. |
| `ALERT_DISCORD` | A Discord webhook: posted `{content, username, allowed_mentions: {parse: []}}` (no `@everyone` from a fault's words; 2000 characters at most). A 429 is waited for as Discord says (`retry_after`, five seconds at most) and asked once more. |
| `ALERT_WEBHOOK` | Any other address: `{text, level, source}`. |
| `ALERT_NAME` | Who it is from. |
| `ALERT_FAULTS` | `on`: every fault `server on failure` hears is an alert, at most once in ten minutes for the same call and words (`AlertSeen`). |

`alertSend(text, level)` gives `{sent, failed}` and never fails: one
webhook that does not take it is in `failed` (and in the log), and the
others still go. A webhook's address is its own secret (whoever has it can
post): keep it out of the source and the page.

Not met Slack or Discord: run against stand-ins (`tests/all.sh real_svc_more`).
To check: an incoming webhook in a Slack workspace, a webhook in a Discord
channel's settings, and `alertSend("hello", "info")`.
