From a8639082826b5f853b54dd0b327fe96c8bbd8233 Mon Sep 17 00:00:00 2001 From: Iam54r1n4 Date: Sun, 26 Jan 2025 11:50:18 +0000 Subject: [PATCH] Add api/v1/config/telegram/... endpoints --- .../routers/api/v1/config/telegram.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 core/scripts/webpanel/routers/api/v1/config/telegram.py diff --git a/core/scripts/webpanel/routers/api/v1/config/telegram.py b/core/scripts/webpanel/routers/api/v1/config/telegram.py new file mode 100644 index 0000000..f74c2b4 --- /dev/null +++ b/core/scripts/webpanel/routers/api/v1/config/telegram.py @@ -0,0 +1,25 @@ +from fastapi import APIRouter, HTTPException +from ..schema.response import DetailResponse +from ..schema.config.telegram import StartInputBody +import cli_api + +router = APIRouter() + + +@router.get('/start', response_model=DetailResponse) +async def start(body: StartInputBody): + try: + cli_api.start_telegram_bot(body.token, body.admin_id) + return DetailResponse(detail='Telegram bot started successfully.') + except Exception as e: + raise HTTPException(status_code=400, detail=f'Error: {str(e)}') + + +@router.get('/stop', response_model=DetailResponse) +async def stop(): + try: + cli_api.stop_telegram_bot() + except Exception as e: + raise HTTPException(status_code=400, detail=f'Error: {str(e)}') + +# TODO: Maybe would be nice to have a status endpoint