Phase 8: widgets and polish
- Live job card widget (progress bar, in-widget cancel via widget_query) and live invoice widget (QR drawn from a bitmap, countdown, paid state), Bot API 10.4 sendWidget, private chats only - Automatic fallback to the ordinary message when sendWidget fails, with a breaker that pauses widgets after repeated failures or on servers without the method; TELEGRAM_WIDGETS - Prometheus metrics on the core (/metrics) and on every worker: queue depth and wait, slots, heartbeats, job outcomes, errors per site, deliveries, cache, invoices, Lightning, ledger check, widgets - Example Prometheus config and alert rules, Caddyfile, dashboard notes - Load test: cmd/loadtest and deploy/loadtest (make loadtest) - Browser check of the widgets' HTML, including decoding a drawn QR - docs/DEPLOY.md (production in under an hour) and docs/MONITORING.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f1f9c6156c
commit
3c153af97f
@@ -50,6 +50,9 @@ phase; sections for later phases say so.
|
||||
| `internal/i18n` | go-i18n wrapper, locale aware formatting. |
|
||||
| `internal/tg` | Narrow Bot API interface, error helpers, the fake Bot API server. |
|
||||
| `internal/api` | HTTP server: health check, payment webhook, worker protocol, Mini App API. |
|
||||
| `internal/widget` | The HTML widgets (status, invoice), their size limits, state encoding, the QR bitmap, the fallback breaker. |
|
||||
| `internal/metrics` | Prometheus metrics of the core (read at scrape time where possible) and of the worker. |
|
||||
| `cmd/loadtest` | Simulated users against a core on the fake Bot API. |
|
||||
| `web/miniapp` | The Mini App front end (Vite, React, TypeScript) and its build, embedded with `go:embed`. |
|
||||
| `locales` | Translation catalogs, embedded in the binary. |
|
||||
|
||||
@@ -404,6 +407,42 @@ The build writes a hash of its sources next to its output and a Go test
|
||||
recomputes it, which catches a source change committed without a rebuild.
|
||||
The Docker image rebuilds the front end from source.
|
||||
|
||||
## Live widgets
|
||||
|
||||
Widgets (Bot API 10.4 `sendWidget`) are an extra layer on top of the
|
||||
ordinary messages, in `internal/bot/live.go`. Nothing else in the bot
|
||||
knows about them:
|
||||
|
||||
- `setStatus` first offers the status to `liveStatus`. In a private chat,
|
||||
the first status of a delivery is sent as a widget; if that works, the
|
||||
card is deleted and the widget becomes the delivery's status message
|
||||
(recorded in `widget_messages`). Later statuses change only the
|
||||
widget's state (`editMessageWidgetData`), throttled like edits.
|
||||
`finalStatus` writes the end state. If `sendWidget` fails, `setStatus`
|
||||
edits the card as it always did.
|
||||
- `sendInvoice` first tries `sendInvoiceWidget`. The widget message keeps
|
||||
the ordinary invoice's caption (with the copyable BOLT11) and buttons;
|
||||
paid and expired are shown by editing the caption as before, plus the
|
||||
widget's state.
|
||||
- The widgets' HTML is the same for every language. All texts, the
|
||||
direction and the button label travel in the state, already
|
||||
translated. The invoice QR is packed as a bitmap in the public data and
|
||||
drawn on a canvas, because a QR library would not fit the 4 KB limit.
|
||||
- The status widget's Cancel sends a request (`widget_query`). The bot
|
||||
finds the delivery by the message, checks that the person tapping owns
|
||||
it, cancels through the same path as `/cancel`, and answers.
|
||||
- `widget.Breaker` pauses attempts after repeated failures, so a Bot API
|
||||
server without widgets costs one failed call per pause, not one per
|
||||
message.
|
||||
|
||||
## Metrics
|
||||
|
||||
`internal/metrics` registers counters that code increments (job outcomes,
|
||||
errors per site, deliveries, widgets, updates), a histogram of queue wait
|
||||
and, at scrape time, gauges read from the database and the services
|
||||
(queue depth, running jobs, slots, worker heartbeats, cache, invoices,
|
||||
Lightning, ledger check). Every method is a no-op on a nil `*Metrics`.
|
||||
|
||||
## Internationalization
|
||||
|
||||
Handlers never contain user-facing text. They call `i18n.Bundle` with a
|
||||
|
||||
Reference in New Issue
Block a user