feat: add Telegram bot integration

Bridges Telegram messages to Timmy via python-telegram-bot (optional
dependency). The bot token can be supplied through the TELEGRAM_TOKEN
env var or at runtime via the new POST /telegram/setup dashboard
endpoint, which (re)starts the bot without a restart.

Changes:
- src/telegram_bot/bot.py — TelegramBot singleton: token persistence
  (telegram_state.json), lifecycle (start/stop), /start command and
  message handler that forwards to Timmy
- src/dashboard/routes/telegram.py — /telegram/setup and /telegram/status
  FastAPI routes
- src/dashboard/app.py — register telegram router; auto-start/stop bot
  in lifespan hook
- src/config.py — TELEGRAM_TOKEN setting (pydantic-settings)
- pyproject.toml — [telegram] optional extra (python-telegram-bot>=21),
  telegram_bot wheel include
- .env.example — TELEGRAM_TOKEN section
- .gitignore — exclude telegram_state.json (contains token)
- tests/conftest.py — stub telegram/telegram.ext for offline test runs
- tests/test_telegram_bot.py — 16 tests covering token helpers,
  lifecycle, and all dashboard routes (370 total, all passing)

https://claude.ai/code/session_01CNBm3ZLobtx3Z1YogHq8ZS
This commit is contained in:
Claude
2026-02-22 17:16:12 +00:00
parent c7388f1585
commit bb93697b92
10 changed files with 456 additions and 0 deletions

View File

@@ -47,6 +47,11 @@ swarm = [
voice = [
"pyttsx3>=2.90",
]
# Telegram: bridge Telegram messages to Timmy via python-telegram-bot.
# pip install ".[telegram]"
telegram = [
"python-telegram-bot>=21.0",
]
[project.scripts]
timmy = "timmy.cli:main"
@@ -66,6 +71,7 @@ include = [
"src/voice",
"src/notifications",
"src/shortcuts",
"src/telegram_bot",
]
[tool.pytest.ini_options]