Phase 6: Mini App

A Telegram Mini App served by the core under /app/, embedded in the binary.

- API under /app/api/ with initData validated (HMAC, age) on every call
- Pages: Home, Queue, Buy (target, product, invoice), History, Groups,
  group detail (Overview, Settings, Wallet, Usage) and Me
- Every action runs through the same service, billing and scheduler code
  as the chat, so limits, prices and admin checks are decided on the server
- Texts come from the catalog over the API; layout mirrors for RTL
- Front end in web/miniapp (Vite, React, TypeScript); the build is
  committed and guarded by a source hash test; the Docker image rebuilds it
- MINIAPP_ENABLED with an https PUBLIC_URL; entry points from /app, group
  settings and the over-limit offer
- Browser test (make miniapp-e2e) against a core in test mode
- Fix: each download attempt gets its own scratch directory, so a retry
  cannot lose its file to the cleanup of the failed attempt

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 10:27:20 +00:00
co-authored by Claude Fable 5.2
parent 51371da0e0
commit 4f11f939a0
55 changed files with 7069 additions and 6 deletions
+23
View File
@@ -9,6 +9,8 @@ import (
"bufio"
"errors"
"fmt"
"net"
"net/url"
"os"
"reflect"
"sort"
@@ -427,6 +429,19 @@ func (c Config) Validate() error {
if c.Queue.Heartbeat.D() >= c.Queue.Lease.D() {
errs = append(errs, "QUEUE_HEARTBEAT must be shorter than QUEUE_LEASE")
}
if c.MiniApp {
// Telegram only opens Mini Apps over HTTPS. A plain http address
// is accepted for this machine itself, for development and tests.
u, err := url.Parse(c.PublicURL)
switch {
case c.PublicURL == "":
errs = append(errs, "PUBLIC_URL is required when MINIAPP_ENABLED=true")
case err != nil || u.Host == "":
errs = append(errs, "PUBLIC_URL is not a URL")
case u.Scheme != "https" && !isLoopback(u.Hostname()):
errs = append(errs, "PUBLIC_URL must start with https:// when MINIAPP_ENABLED=true")
}
}
if c.Storage.Backend == "s3" {
if c.Storage.S3.Endpoint == "" || c.Storage.S3.Bucket == "" {
errs = append(errs, "S3_ENDPOINT and S3_BUCKET are required when STORAGE_BACKEND=s3")
@@ -519,6 +534,14 @@ func (c Config) RequiredTags(site string) string {
return strings.Join(tags, ",")
}
func isLoopback(host string) bool {
if host == "localhost" {
return true
}
ip := net.ParseIP(host)
return ip != nil && ip.IsLoopback()
}
// MiniAppEnabled reports whether Mini App links can be shown. The Mini App
// is served from PublicURL, so both are needed.
func (c Config) MiniAppEnabled() bool { return c.MiniApp && c.PublicURL != "" }
+17
View File
@@ -167,6 +167,23 @@ func TestValidate(t *testing.T) {
func(c *Config) { c.Worker.Concurrency = 0 },
func(c *Config) { c.Queue.MaxAttempts = 0 },
func(c *Config) { c.Queue.Heartbeat = c.Queue.Lease },
func(c *Config) { c.MiniApp = true }, // no public URL
func(c *Config) { c.MiniApp, c.PublicURL = true, "http://bot.example.com" },
func(c *Config) { c.MiniApp, c.PublicURL = true, "bot.example.com" },
}
good := []func(*Config){
func(c *Config) { c.MiniApp, c.PublicURL = true, "https://bot.example.com" },
func(c *Config) { c.MiniApp, c.PublicURL = true, "http://127.0.0.1:8080" },
func(c *Config) { c.MiniApp, c.PublicURL = true, "http://localhost:8080" },
func(c *Config) { c.PublicURL = "http://bot.example.com" }, // fine without the Mini App
}
for i, mut := range good {
cfg := Default()
cfg.Telegram.Token = "x"
mut(&cfg)
if err := cfg.Validate(); err != nil {
t.Errorf("good case %d: %v", i, err)
}
}
for i, mut := range bad {
cfg := Default()