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
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Runs the browser test of the Mini App: a complete core in test mode
# (fake Telegram, fake LNbits, scripted yt-dlp) and headless Chromium
# clicking through the built app.
#
# web/miniapp/e2e/run.sh [screenshot dir]
#
# Needs Node.js with "npm ci" done in web/miniapp, and a Chromium that
# Playwright can start: "npx playwright-core install chromium", or
# CHROMIUM_PATH pointing at a Chrome or Chromium binary.
set -euo pipefail
root="$(cd "$(dirname "$0")/../../.." && pwd)"
stage="$(mktemp -d)"
shots="${1:-}"
log="$stage/core.log"
cleanup() {
touch "$stage/stop"
wait "$core" 2>/dev/null || true
rm -rf "$stage"
}
cd "$root"
(cd web/miniapp && npm run build >/dev/null)
DLBOT_STAGE_DIR="$stage" go test ./internal/app/ -run '^TestMiniAppStage$' -count=1 -timeout 20m >"$log" 2>&1 &
core=$!
trap cleanup EXIT
for _ in $(seq 1 600); do
[ -f "$stage/stage.json" ] && break
if ! kill -0 "$core" 2>/dev/null; then
echo "the core did not start:" >&2
cat "$log" >&2
exit 1
fi
sleep 0.2
done
[ -f "$stage/stage.json" ] || { echo "timed out waiting for the core" >&2; cat "$log" >&2; exit 1; }
(cd web/miniapp && node e2e/smoke.mjs "$stage" "$shots")