* feat(notify): every person chooses what reaches their own Telegram Loki is multi-tenant, but Telegram was one hard-wired chat (the operator's) on a bot whose incoming messages belong to OpenClaw. Now each account sets it up in Settings → Notifications → Telegram: - Connect Telegram opens Loki's notification bot with a one-time code; pressing Start links that chat (POST /api/telegram/webhook, verified by Telegram's secret-token header). No chat ids, nothing to type. /stop or blocking the bot unlinks. The webhook registers itself on first use. - Six kinds of message (config/notify-categories.ts), each on/off per person; "servers" is shown to the operator only. - Every app sender now goes through the gateway as that person (lib/notify/person.ts → deliverNotice): approvals, feedback, fixes, runs, studio, build requests, sign-ups, autopilot, site live, gateway down. The gateway applies the person's choices, sends to their own linked chat, and falls back to the operator's old chat for the operator only. scripts/test/one-telegram-door.ts fails the build on a direct send. - Buttons Loki composes from its own records (a customer's own site) are trusted; links from outside still meet the host allowlist. - Migration 0132 adds the link and choices to notification_preferences. - New env: TELEGRAM_NOTIFY_BOT_TOKEN, TELEGRAM_NOTIFY_BOT_USERNAME (checked as a pair at boot). Until set, Settings says Telegram is not set up and the operator's existing chat keeps working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtzUbLhg3oqt4X1NaN * fix(openclaw): the heartbeat follows the same one-tap contract The box audit (openclaw-day-plan run 3) found the sender of "Gateway was not running. Restarted automatically. All good now.": the OpenClaw workspace's tools/health-guardian.sh, not in any repo, whose status lines the agent relays. The contract now goes on HEARTBEAT.md too (between markers, backed up, idempotent), and the installer prints how health-guardian is started and its speaking lines, numbers and secrets redacted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtzUbLhg3oqt4X1NaN * style(drizzle): format the generated 0132 snapshot and journal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtzUbLhg3oqt4X1NaN --------- Co-authored-by: Claude <noreply@anthropic.com>
22 KiB
Telegram notifications — the registry
This file is the SSOT for everything that reaches the operator's Telegram.
If something pings the phone and is not listed here, that is a bug — and CI
enforces it: scripts/ci/check-telegram-registry.sh fails when a file in this
repo sends to Telegram (directly, via telegram-send.ts, or via the box's
lib-alert.sh) without being registered below. Adding a notification =
adding it here in the same PR. Removing one = removing its row.
The contract: one tap, or not at all (2026-11-02)
The owner, after a night of ⚙️ STILL FAILING: run-p… every five minutes:
If you send me something, it has to be important for me … and then it should be actionable. I should read it and click one time, I shouldn't write anything there. "What exactly should I do with that information?" — this question should never appear in my mind.
So, enforced in code, not in this file:
- No button, no message.
sendTelegramMessage/sendTelegramVoice(src/lib/actions/telegram-send.ts) refuse a message without at least one URL button (NOT_ACTIONABLE). A button is a verb and the https link that does the thing, or opens the exact screen where one tap does it. - Everything else is the list's. What has no tap is recorded on /today or
/system (
alertsrows of typenotice/system_event) and never reaches the phone. - One gateway for every bot.
deliverNotice(src/lib/notify/deliver.ts) appliessrc/lib/notify/policy.ts: at most 3 buttons; one incident is one message, reminders back off 30m → 2h → 8h → daily; at most 3 messages per source per hour and 12 a day, whatever a sender's bug; onlyurgency: "now"makes a sound, and never between 22:00 and 07:00 Zurich. Callers:POST /api/notify— anything holding a Loki agent token (OpenClaw jobs vialoki.sh notify, scripts);POST /api/notify/box— the box'slib-alert.sh(_alert_deliver);src/lib/notify/box.tsdecides what a box line is. Today only a sign that someone is IN the box, and a Hetzner rescale window, have a button;POST /api/orangecat/notify— OrangeCat's bots, signed withORANGECAT_WEBHOOK_SECRET.
- Voice notes are a paid feature. A notice with
voice: truearrives as a voice note (Groq studio voice → OGG/Opus,src/lib/notify/voice.ts) for an account on a paid plan; a free account gets the text, and once a month one notice saying what voice notes cost, with the button to get them. - Test runs (
ALERT_DRY_RUN=1) never deliver.
Whose news. The chat is the operator's. News about ONE account's work —
a visitor's note on their site, their run, their fix, their night — goes to
Telegram only when that account is the operator's
(src/lib/actions/telegram-for-user.ts); every other account hears through
its own push and alerts. Before 2026-10-19 every customer's feedback reached
this chat.
Requested updates (the operator asked for these — keep them)
| What arrives | Trigger | Source |
|---|---|---|
| 📨 New visitor feedback (project, excerpt, link to inbox) | A genuine visitor submits the feedback form (POST /api/feedback; AI/synthesizer filings stay silent) |
src/lib/feedback/notify-new.ts |
| 🏛 New studio brief / partner application, or activity on one (the visitor's words, the website, a link to the review view) | A visitor or partner creates a studio request (POST /api/studio-intake) or acts on one through their private portal (a reply, course evidence, a profile, preview acceptance, a delivery). Replayed receipts stay silent. The operator must act on it: the page promises a person reads it |
src/lib/studio/notify.ts |
| 🛠 Build request for a site (the visitor's words, a link to Build requests on /approvals) | An account that may not use the fleet's builder taps "Make it real" on /change (POST /api/projects/from-website). A repeat of the same brief stays silent. The operator must act on it: the visitor was told a person reads it first |
src/lib/build-requests/notify.ts |
✅ A fix reached the live site, or 🚨 a merged fix failed to deploy (project, the visitor's words, the pull request, and for a live fix ▶ Watch the fix — /feedback/<id>/watch-fix, which mints a fresh walkthrough ticket on every open so the link outlives the message) |
The fix ledger sees a run's pull request TRANSITION into deployed or deploy-failed while the inbox is read — once per fix, never on re-reads. Says when Loki merged it automatically, because that is the fact an operator needs to keep trusting the switch | src/lib/feedback/notify-shipped.ts |
| 🌐 <project> is live (the site URL, plus the owner's link that readies the widget so what they say there gets built) | A project with a repository but no live URL is found live — a green deploy of main AND a public response — by the hourly check-site-live cron or when the owner opens the project page. Once per project: the live URL it writes is what stops the check. Operator's own projects only; other owners get the same as a push |
src/lib/site-live-reconcile.ts |
| 🧾 Waitlist signup / 📬 New subscriber (source, address) | Someone joins a list via POST /api/newsletter — the studio site's /hire/ waitlist sends source: bitbaum-hire. Only a genuinely NEW row announces; a repeat signup stays silent. The operator must act on it: the page promises a human writes back when capacity opens |
src/lib/newsletter/notify-signup.ts |
| 📋 Tonight's autopilot plan — needs your yes: what would be built and read, what it would cost from the owner's own last runs, with ✅ Approve / ✕ Reject buttons (no Edit — a plan is yes or no) | The autopilot-plan cron (19:00 UTC) finds something to run tonight and no allowance covers it. One card per night; a night with nothing to build sends nothing. Every account also gets it as a push |
src/lib/actions/notify-decision.ts (card), src/lib/autopilot-night.ts (push) |
| 🌙 Tonight runs without asking (until when, under what cap) + the same plan line | The autopilot-plan cron approves tonight's plan under the allowance the owner set in Settings → Autopilot — told the evening before, never the morning after |
src/lib/autopilot-night.ts |
| 🌙 While you were away: what the autopilot night did, with See what changed — only when it started fixes; a night that built nothing is on /feedback and in the push, not Telegram | The autopilot-night cron (02:30 UTC) |
src/lib/autopilot-night.ts |
| Run outcome of a run that did NOT succeed, with Open <project> on Home (Retry and the provider switch live there). A success is posted to the thread that asked and to push, not Telegram | An orchestration run with notifyOnClose closes |
src/lib/orchestration/notify-close.ts, src/lib/orchestration/gate-and-close.ts (⏸ goal stopped, Decide on Control) |
Morning brief (its prompt is reviewed in scripts/openclaw/day-plan/morning-brief.md and installed by .github/workflows/openclaw-day-plan.yml, which also switches off jobs that only post machine warnings, appends scripts/openclaw/day-plan/contract.md to every other enabled job (send only what has one link that does it, otherwise NO_REPLY) and digest-contract.md to the summaries he asked for (at most five lines, each with its link), puts the same contract on the OpenClaw heartbeat (HEARTBEAT.md, which relays workspace/tools/health-guardian.sh status lines), and lists, by path, every file on the box that calls the Telegram API — scripts/openclaw/day-plan/install.sh only searches for that string, it sends nothing), evening wrap, weekly reflection, Monday digest, email deadlines, financial scan, life scorecard |
Loki's scheduled jobs — schedules live in their own SSOT: /home/openclaw/.openclaw/cron/jobs.json on bitbaum (edit via Loki, not here) |
off-repo: OpenClaw cron |
Incidents (something is broken; a fix agent is already dispatched)
Every box row below now goes through lib-alert.sh → POST /api/notify/box:
it is recorded on /system and reaches the phone only where this table names a
button. When Loki itself cannot be reached, only an intrusion goes to Telegram
directly, with an "Open Box doctor" button.
| What arrives | Trigger | Source |
|---|---|---|
| 🔴 DOWN: <unit> — <app error> → 🤖 fix agent dispatched | A systemd unit fails and stays failed past the grace window | scripts/hetzner/install-host-alerts.sh (notify-failure.sh) |
⚙️ STILL FAILING: a; b / ✅ RECOVERED: a; b — on /system only, never the phone (one row, count rising). Transient systemd-run units (run-p<pid>-i<id>) are cleared, never listed; appcron-* oneshots are the OnFailure notifier's |
The 5-min sweep sees a unit failed on two consecutive ticks / recover | scripts/hetzner/install-host-alerts.sh (host-check.sh) |
| 🔧 FIXED (no action needed): <what was repaired> | host-check auto-repaired an unreadable app .env and restarted the app |
scripts/hetzner/install-host-alerts.sh (host-check.sh) |
| 💾 DISK / 🧠 MEM / 🐘 POSTGRES transitions | Resource crosses its hysteresis band on the box | scripts/hetzner/install-host-alerts.sh (host-check.sh) |
| Loki is down and restarting it did not help, with Redeploy Loki (the Deploy workflow). Auto-fixed / recovered go to /system via lib-alert, not the phone | Every 15 min (ivy-health.timer); re-pages at most every 4h. Installed by .github/workflows/install-box-alerts.yml |
scripts/hetzner/ivy-health.sh |
| 🔴 DOWN: <app> (<url>) → HTTP <code> / ✅ RECOVERED (on-box) | An app URL in targets.conf stops answering | scripts/hetzner/install-watchdog.sh (watch.sh; also the external dead-man's-switch ping) |
| Loki is not answering from outside (Redeploy Loki), or 3+ apps stopped answering at once (Run Box doctor). One app down is its GitHub issue and the on-box fix agent's, not a message | GitHub-side hourly sweep — still reports when bitbaum itself is dead | .github/workflows/fleet-uptime.yml (probe: scripts/hetzner/uptime-sweep.sh) |
| 🚨 Loki deploy failed and the rollback failed too, with Redeploy Loki. A clean rollback is not paged | A loki deploy fails and cannot roll back | scripts/deploy-hetzner.sh |
| 🧩 <app>: <runtime conformance finding> — on /system only. A sleeping app (wake socket listening) is not a finding | Deployed reality diverges from the register (wrong port, dead tunnel, inactive unit) | scripts/hetzner/install-runtime-conformance.sh |
| 🧪 <provider/model>: <n> failure(s) in 24h | A model link keeps failing while the fallback chain hides it — Groq answered 400 to every structured Cat call for days and nothing said so | scripts/hetzner/ai-provider-check.sh (installed by scripts/hetzner/install-ai-provider-watch.sh) |
| 🔑 <provider/model>: API KEY REJECTED | A model link fails with 401/403 — the key itself is revoked, so it fails every call until replaced. Replace the key in the app's env file and restart the app | scripts/hetzner/ai-provider-check.sh |
| 🔑 <vendor>: DEAD API KEY #<fp> in: <apps> | A vendor rejects a key held by those apps (checked hourly, no tokens spent, every env file in both box layouts). Names the apps and a working key of the same vendor. orangecat's Groq key was dead for days in 2026-10 and only the mic broke visibly | scripts/hetzner/api-key-check.sh (installed by scripts/hetzner/install-api-key-watch.sh) |
| 🧪 loki e2e FAILED: … / ✅ RECOVERED | End-to-end check of the live site as the operator, ON DEMAND only since 2026-09-25 (no timer: it sends a real chat turn, and a timer may not spend the shared free AI tier): fleet question answered from the map, map published, dispatch returns to its thread (when the builder is authenticated) | scripts/hetzner/loki-e2e-check.sh (installed by scripts/hetzner/install-loki-e2e-watch.sh; test: scripts/test/loki-loop-e2e.ts) |
| Loki check: Telegram delivery works from the box | ONE test message, ON DEMAND only: someone dispatches the Box doctor workflow with send_test true (the default) — never scheduled, never on a push. It exists to answer "does a message from the box reach the phone at all?" when notifications stop arriving |
scripts/hetzner/doctor-messaging.sh (run by .github/workflows/box-doctor.yml) |
| 🔌 the gateway behind WhatsApp and the Telegram chat is down, with Restart the gateway (the OpenClaw gateway up workflow). Its return is not paged | The check-gateway cron (every 10 min) cannot reach the OpenClaw gateway on :18789 — once per outage |
src/app/api/crons/check-gateway/route.ts |
| 🔑 builder auth DISABLED / 🔌 builder probe got no answer / ✅ RECOVERED | Hourly probe runs Claude Code with the box-runner’s own token; the token dies with the Claude account that minted it and every dispatch then hangs silently (2026-09-14) | scripts/hetzner/builder-auth-check.sh (installed by scripts/hetzner/install-builder-auth-watch.sh) |
| 🚫/🧟 agent-work findings | Hourly sweep finds stranded/zombie agent work on the box | scripts/hetzner/agent-work-check.sh (installed by scripts/hetzner/install-agent-work-watch.sh) |
| 🧹/🚨 DISK GC non-routine outcome | GC ran but the disk is still above the warn mark, or nothing was reclaimable (routine success is journal-only) | scripts/hetzner/install-disk-gc.sh |
| Fleet refs audit findings | Deployed refs diverge from expected across the fleet | scripts/hetzner/install-fleet-refs-audit.sh |
| ✗ register check findings | Daily 09:15 (laptop): committed apps.conf register vs reality — at most one message per finding per day | scripts/local/fleet-register-check |
Threat detection (something changed that only an operator can judge)
Baselines are seeded silently on the first run; every row below fires on
CHANGE only and ends with what to do. Blocking a web scanner is a response,
not a message (fail2ban caddy-scan, journal only).
| What arrives | Trigger | Source |
|---|---|---|
| 🧱 FIREWALL DOWN / 🛡️ GUARD DOWN / 🔓 SSHD DRIFT / ✅ RECOVERED | ufw, fail2ban or unattended-upgrades stops; sshd stops being keys-only (as sshd -T resolves it) |
scripts/hetzner/install-security-watch.sh (security-check.sh, 5-min timer) |
| 📝 N SENSITIVE FILE(S) CHANGED: a, b, c (+k more) | A file an intruder edits to persist changes hash, owner or mode: sshd/sudoers/authorized_keys/shadow/cron/PAM/ld.so.preload/Caddy/ufw/monitoring/systemd units/apt sources — one grouped message per tick | scripts/hetzner/install-security-watch.sh (security-check.sh) |
| 🔌 NEW PORT OPEN TO THE INTERNET / 👤 NEW PRIVILEGED ACCOUNT / 🐳 NEW CONTAINER / 🧨 NEW SETUID BINARY | A non-loopback listener, a uid-0/shell/sudo/docker account, a container or a setuid binary appears that was not in the baseline | scripts/hetzner/install-security-watch.sh (security-check.sh) |
| 🔑 SSH LOGIN as <user> from <ip> / 🚨 SSH PASSWORD LOGIN ACCEPTED | A key login from an IP never seen in 30 days of history that is not a GitHub Actions runner (api.github.com/meta, cached daily); any password login at all | scripts/hetzner/install-security-watch.sh (security-check.sh) |
| ☠️ SUSPICIOUS PROCESS | A process executing from /tmp, /dev/shm or /var/tmp, or a known miner name | scripts/hetzner/install-security-watch.sh (security-check.sh) |
| 🗄️ OFFSITE BACKUP STALE / UNREACHABLE / ✅ RECOVERED | Newest restic snapshot older than 30h, or restic cannot list them (hourly) | scripts/hetzner/install-security-watch.sh (security-check.sh) |
| ♻️ REBOOT PENDING for N days | A kernel/security patch has waited on a reboot for more than a week (weekly at most) | scripts/hetzner/install-security-watch.sh (security-check.sh) |
| 🕵️ N SECRET(S) IN REPO <repo>: <type>×n / 🛡️ NEW CRITICAL DEPENDENCY ALERT(S) / 🌍 REPO NOW PUBLIC / 🔍 SECRET SCANNING OFF / 🧑💻 NEW ACCESS TO THE ORG / 🗝️ NEW DEPLOY KEY / 🎬 ACTIONS POLICY LOOSENED / 🐙 GITHUB CHECK BLIND | Daily read of the GitHub org through the box's gh login; secret alerts are read per repo (the org endpoint is blind), forks are skipped, and N new alerts in one repo are ONE message — the per-alert version sent 100 on 2026-09-14. A call the token cannot make is skipped (journal), never read as a value | scripts/hetzner/install-security-watch.sh (github-security-check.sh, daily 07:10) |
| 🔌 laptop: NEW PORT / 🔓 laptop: sshd is RUNNING / 🖥️ laptop: screen lock off / 🛡️ laptop: upgrades OFF / 🔑 laptop: ~/.ssh changed / 👤 laptop: NEW LOGIN ACCOUNT / 🐙 laptop: gh identity changed / ♻️ laptop: reboot pending | The operator's laptop (box SSH key, admin:org token, transcripts) every 30 min, on change only; delivered through the box's lib-alert.sh over SSH, desktop notification if the box is unreachable |
scripts/local/laptop-security-check (user timer laptop-security-check.timer) |
Loki self-checks (the platform watching itself)
| What arrives | Trigger | Source |
|---|---|---|
| Approvals waiting — with one-tap ✅ Approve / ✕ Reject / ✏️ Edit buttons when exactly one item is waiting, otherwise a link to the queue | Proposed actions sit undecided for over an hour; one message per episode, never per draft | src/app/api/crons/check-pending-approvals/route.ts |
| 📋 <type> — needs your yes (the decision itself: what, when, where, plus Approve / Reject / Edit buttons) | A draft is queued from something the operator asked for in words, and no standing approval covers it. Spontaneous proposals (check-ins, the advisor) never send this — they wait for the hourly digest above | src/lib/actions/notify-decision.ts |
| 📅 Booked — <event>, with a link into Google Calendar | A calendar event really reaches executed (says so only after gog succeeded, which is usually minutes after approval and in a different process). Names the standing approval when one acted on the operator's behalf, so an action taken without asking is never silent |
src/lib/actions/notify-decision.ts, called from src/lib/actions/execute-action.ts and src/app/api/actions/drain-events/route.ts |
| ⚠️ Not booked / Not done — <action> (what, the details, why, and Open in Loki) | An approved calendar event failed to book MAX_BOOKING_ATTEMPTS (3) times in a row: Loki stops retrying, marks it expired and says so ONCE. Before 2026-10-08 a failed booking retried every 15 s forever and nobody heard |
src/lib/actions/notify-decision.ts (notifyActionGaveUp, called from src/app/api/actions/drain-events/route.ts) |
| Feedback needs you (stalled Implement / no agent / Check live) | A dispatched fix is stuck or live and waiting for Confirm — one ping when the flag goes up | src/app/api/crons/check-feedback-needs-you/route.ts, src/lib/feedback/notify-needs-you.ts |
| Run escalation | A run needs the operator's decision to proceed | src/db/queries/run-escalations.ts |
| 📊 Ledger-ready (one-shot) | Run ledger reaches the improver threshold; self-disables after firing | scripts/hetzner/ledger-ready-gate.sh |
| 🏷 Rescale window (hcloud) | A bigger Hetzner tier becomes available for migration in fsn1 | scripts/hetzner/hcloud-availability.sh |
Telemetry stale, runner stalled / behind, and model-id rot used to ping too; since 2026-11-02 they are /system alerts only — none has a one-tap answer.
Per person: each account chooses (2026-11-02)
Loki is multi-tenant, so Telegram is each person's own, set up in Settings → Notifications → Telegram:
- Connect Telegram opens Loki's notification bot (
TELEGRAM_NOTIFY_BOT_TOKEN,TELEGRAM_NOTIFY_BOT_USERNAME) with a one-time code; pressing Start links that chat (POST /api/telegram/webhook,src/db/queries/telegram-links.ts; the bot itself issrc/lib/telegram/notify-bot.ts, per-person sendssrc/lib/telegram/send-to-person.ts, the Settings APIsrc/app/api/telegram/link/route.ts). Nobody types a chat id./stopor blocking the bot unlinks it. - Each kind of message (
src/config/notify-categories.ts: decisions, people, results, plans, other assistants, servers — the last operator-only) is on or off per person. - Every app sender goes through
deliverNotice(directly or viasrc/lib/notify/person.ts), which applies the person's choices and sends to their own linked chat.scripts/test/one-telegram-door.tsfails the build if any app code calls Telegram another way. - The operator's chat from before (
APP_TELEGRAM_CHAT_ID, the OpenClaw bot) keeps receiving his notices until he connects through Settings.
Every bot's way in
| Who | How | Code |
|---|---|---|
| Any token holder (OpenClaw jobs, scripts) | POST /api/notify · loki.sh notify "<title>" "<button>" "<url>" |
src/app/api/notify/route.ts, scripts/openclaw/loki-skill/scripts/loki.sh |
| The box | POST /api/notify/box from lib-alert.sh |
src/app/api/notify/box/route.ts, src/lib/notify/box.ts |
| OrangeCat's bots | POST /api/orangecat/notify, signed |
src/app/api/orangecat/notify/route.ts |
| A notice asking for a voice note | voice: true — paid plans hear it; others get the text and a monthly "voice notes come with Personal" notice |
src/lib/notify/deliver.ts, src/lib/notify/voice.ts |
Off-repo senders (registered here, owned elsewhere)
| Sender | What | Its own SSOT |
|---|---|---|
| Loki (OpenClaw) | Conversation, briefings, reminders — everything conversational | /home/openclaw/.openclaw/cron/jobs.json + OpenClaw config on bitbaum |
| orangecat repo | orangecat.ch uptime alerts | orangecat/.github/workflows/uptime.yml |
Rules for adding a notification
- Ask the channel question first: must the operator act, is it an outcome they are waiting for, or did they ask for the digest? If none — journal, not Telegram.
- Route through the shared machinery — the only two blessed send paths:
lib-alert.shon the box (installed byscripts/hetzner/install-host-alerts.sh; usealert_once/alert_transitionwith a human subject) andsrc/lib/actions/telegram-send.tsin the app (self-only allowlist, fail-closed). A privatecurltoapi.telegram.orgrepeats the 2026-08-28 register-check double-send and is a reviewable smell. - Add the row here, in the same PR. CI (
check-telegram-registry.sh) makes the omission fail loudly. - Test sends never deliver:
ALERT_DRY_RUN=1(box), and never bare-run a sender "to see if it works" — 2026-08-28, a live test rang the phone with a message about nothing.