forked from Rockachopa/Timmy-time-dashboard
Complete the module consolidation planned in REFACTORING_PLAN.md: Modules merged: - work_orders/ + task_queue/ → swarm/ (subpackages) - self_modify/ + self_tdd/ + upgrades/ → self_coding/ (subpackages) - tools/ → creative/tools/ - chat_bridge/ + telegram_bot/ + shortcuts/ + voice/ → integrations/ (new) - ws_manager/ + notifications/ + events/ + router/ → infrastructure/ (new) - agents/ + agent_core/ + memory/ → timmy/ (subpackages) Updated across codebase: - 66 source files: import statements rewritten - 13 test files: import + patch() target strings rewritten - pyproject.toml: wheel includes (28→14), entry points updated - CLAUDE.md: singleton paths, module map, entry points table - AGENTS.md: file convention updates - REFACTORING_PLAN.md: execution status, success metrics Extras: - Module-level CLAUDE.md added to 6 key packages (Phase 6.2) - Zero test regressions: 1462 tests passing https://claude.ai/code/session_01JNjWfHqusjT3aiN4vvYgUk
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
"""Dashboard routes for Telegram bot setup and status."""
|
|
|
|
from fastapi import APIRouter
|
|
from pydantic import BaseModel
|
|
|
|
router = APIRouter(prefix="/telegram", tags=["telegram"])
|
|
|
|
|
|
class TokenPayload(BaseModel):
|
|
token: str
|
|
|
|
|
|
@router.post("/setup")
|
|
async def setup_telegram(payload: TokenPayload):
|
|
"""Accept a Telegram bot token, save it, and (re)start the bot.
|
|
|
|
Send a POST with JSON body: {"token": "<your-bot-token>"}
|
|
Get the token from @BotFather on Telegram.
|
|
"""
|
|
from integrations.telegram_bot.bot import telegram_bot
|
|
|
|
token = payload.token.strip()
|
|
if not token:
|
|
return {"ok": False, "error": "Token cannot be empty."}
|
|
|
|
telegram_bot.save_token(token)
|
|
|
|
if telegram_bot.is_running:
|
|
await telegram_bot.stop()
|
|
|
|
success = await telegram_bot.start(token=token)
|
|
if success:
|
|
return {"ok": True, "message": "Telegram bot started successfully."}
|
|
return {
|
|
"ok": False,
|
|
"error": (
|
|
"Failed to start bot. Check the token is correct and that "
|
|
'python-telegram-bot is installed: pip install ".[telegram]"'
|
|
),
|
|
}
|
|
|
|
|
|
@router.get("/status")
|
|
async def telegram_status():
|
|
"""Return the current state of the Telegram bot."""
|
|
from integrations.telegram_bot.bot import telegram_bot
|
|
|
|
return {
|
|
"running": telegram_bot.is_running,
|
|
"token_set": telegram_bot.token_set,
|
|
}
|