Dmitry Beresnev commited on
Commit
820c4b2
·
1 Parent(s): 47b314d

Add Telegram bot control interface for HuggingFace Spaces deployment

Browse files

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
- TelegramNotifier supports the Apps Script proxy, muting, and broadcast
to dynamically subscribed chats
- RiskEngine.regime property, Telemetry.snapshot()

16 files changed +1132 -8
Files changed (16)
DockerfileAdded+34
app.py+7-2
pyproject.toml+4
src/core/alerting.py+40-6
src/core/config.py+3
src/core/main.py+6
src/core/risk_engine.py+4
src/core/telemetry.py+3
src/telegram_bot/__init__.pyAdded
Empty file
src/telegram_bot/bot_service.pyAdded+340
src/telegram_bot/config.pyAdded+49
src/telegram_bot/controller.pyAdded+195
src/telegram_bot/server.pyAdded+114
src/telegram_bot/telegram_client.pyAdded+93
src/telegram_bot/tg_models.pyAdded+10
uv.lock+230