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
+25 -1
View File
@@ -312,6 +312,25 @@ func (s *Server) PushCallback(chatID, userID int64, messageID int, data string)
return id
}
// PushWidgetQuery queues a request from the widget in a message, as a
// widget_query update. It returns the query ID.
func (s *Server) PushWidgetQuery(chatID, userID int64, messageID int, data string) string {
s.mu.Lock()
defer s.mu.Unlock()
s.msgID++
id := "wq" + strconv.Itoa(s.msgID)
s.pushLocked(map[string]any{"widget_query": map[string]any{
"id": id,
"from": map[string]any{"id": userID, "is_bot": false, "first_name": "User", "language_code": "en"},
"chat": chatObject(chatID),
"message_id": messageID,
"chat_instance": "ci" + strconv.FormatInt(chatID, 10),
"type": map[string]any{"type": "data"},
"data": data,
}})
return id
}
// PushRaw queues an arbitrary update body, for example my_chat_member.
func (s *Server) PushRaw(update map[string]any) {
s.mu.Lock()
@@ -438,7 +457,7 @@ func (s *Server) resultLocked(c *Call) any {
}
uid, _ := strconv.ParseInt(c.Params["user_id"], 10, 64)
return map[string]any{"status": status, "user": map[string]any{"id": uid, "is_bot": false, "first_name": "User"}}
case "sendMessage", "sendPhoto", "sendVideo", "sendAudio", "sendDocument", "sendAnimation":
case "sendMessage", "sendPhoto", "sendVideo", "sendAudio", "sendDocument", "sendAnimation", "sendWidget":
s.msgID++
c.MessageID = s.msgID
msg := s.messageLocked(c)
@@ -447,6 +466,9 @@ func (s *Server) resultLocked(c *Call) any {
case "editMessageText", "editMessageCaption", "editMessageReplyMarkup", "editMessageMedia":
c.MessageID, _ = strconv.Atoi(c.Params["message_id"])
return s.messageLocked(c)
case "editMessageWidgetData", "deleteMessage":
c.MessageID, _ = strconv.Atoi(c.Params["message_id"])
return true
default:
return true
}
@@ -494,6 +516,8 @@ func (s *Server) messageLocked(c *Call) map[string]any {
a := media("animation")
a["width"], a["height"], a["duration"] = 320, 180, 3
msg["animation"] = a
case "sendWidget":
msg["widget"] = map[string]any{"html": c.Params["html"], "chat_data": c.Params["chat_data"], "public_data": c.Params["public_data"]}
}
return msg
}