Add Telegram bot control interface for HuggingFace Spaces deployment
Dmitry Beresnev
820c4b2
The platform is now controlled through Telegram: app.py starts a FastAPI
webhook server (port 7860) while the polling loop runs in a background
thread managed by a new PlatformController.
New src/telegram_bot/ package:
- server.py: webhook endpoint /webhook/{WEBHOOK_SECRET}, health endpoints,
/set_webhook helper for registering the webhook with Telegram
- telegram_client.py: async httpx client routing all outbound calls through
the Google Apps Script proxy (GOOGLE_APPS_SCRIPT_URL) since HF Spaces
blocks direct api.telegram.org traffic; direct fallback for local dev
- bot_service.py: commands /status /regime /universe /events /telemetry
/subscribe /unsubscribe, plus admin-only /pause /resume /mute /unmute
/interval (restricted to TELEGRAM_CHAT_ID when set)
- controller.py: pause/resume flags, runtime poll-interval override,
ring buffers of recent risk events and regime changes
Core changes:
- Runtime now exposes risk, envelope_store and telemetry for the bot
- TelegramNoti…
Aggregate regime decisions once per cycle via system.cycle.completed;
move envelope limits to a policy table and alert building to a pub/sub
bridge; add Runtime dataclass, universe diff/refresh, logging, event
schemas, pytest suite, and updated ASCII architecture docs.