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:
Michilis
2026-11-18 18:24:36 +00:00
co-authored by Claude Opus 5.5
parent f1f9c6156c
commit 3c153af97f
45 changed files with 3158 additions and 20 deletions
+9 -4
View File
@@ -404,6 +404,9 @@ func (b *Bot) invoiceKeyboard(p *db.Purchase) *telego.InlineKeyboardMarkup {
func (b *Bot) sendInvoice(ctx context.Context, chat int64, p *db.Purchase) {
text := b.invoiceText(p)
kb := b.invoiceKeyboard(p)
if b.sendInvoiceWidget(ctx, chat, p, text, kb) {
return
}
// Upper case BOLT11 lets the QR code use its compact alphanumeric mode.
png, err := qrcode.Encode(strings.ToUpper(p.Bolt11), qrcode.Medium, 512)
if err == nil {
@@ -452,11 +455,13 @@ func (b *Bot) showPurchaseState(ctx context.Context, p *db.Purchase) {
lang := p.Lang
switch p.Status {
case db.PurchasePaid:
_ = b.edit(ctx, p.ChatID, p.MessageID, p.MessageIsPhoto, b.paidText(ctx, p), nil)
text := b.paidText(ctx, p)
b.liveInvoice(ctx, p, text)
_ = b.edit(ctx, p.ChatID, p.MessageID, p.MessageIsPhoto, text, nil)
case db.PurchaseExpired:
_ = b.edit(ctx, p.ChatID, p.MessageID, p.MessageIsPhoto, b.tr.HTML(lang, "invoice.expired", i18n.Args{
"Title": b.productTitle(lang, p.Product),
}), nil)
text := b.tr.HTML(lang, "invoice.expired", i18n.Args{"Title": b.productTitle(lang, p.Product)})
b.liveInvoice(ctx, p, text)
_ = b.edit(ctx, p.ChatID, p.MessageID, p.MessageIsPhoto, text, nil)
case db.PurchaseCancelled:
if err := b.api.DeleteMessage(ctx, &telego.DeleteMessageParams{ChatID: chatID(p.ChatID), MessageID: int(p.MessageID)}); err != nil {
_ = b.edit(ctx, p.ChatID, p.MessageID, p.MessageIsPhoto, b.tr.HTML(lang, "invoice.cancelled", nil), nil)