2.9 KiB
2.9 KiB
Telegram
What Changed
The repository now includes a working Telegram MVP flow:
- authenticated users can request a one-time Telegram link code;
- the bot completes linking through
/start LINK_CODE; - linked users can use
/statusand/services; - linked users with role
adminoroperatorcan use/restart SERVER_NAME SERVICE_NAME; - bot-triggered restart actions are recorded with
actor_source="telegram"; - authenticated users can send a test message through
POST /api/v1/telegram/test-message.
Configuration
Required environment variables:
TELEGRAM_BOT_TOKENTELEGRAM_BOT_API_SECRETTELEGRAM_MODETELEGRAM_LINK_CODE_EXPIRE_MINUTES
Bot runtime variables:
BACKEND_API_BASE_URLDefault in the bot process ishttp://backend:8000/api/v1
Notes:
TELEGRAM_BOT_API_SECRETmust match in both backend and bot environments;TELEGRAM_BOT_TOKENmust belong to the bot that will receive user commands;- link codes expire automatically after the configured number of minutes.
Linking Flow
- Sign in to the panel or call the API with a valid user token.
- Request a link code:
curl -X POST http://localhost:8000/api/v1/telegram/link \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
- Open Telegram and send the bot:
/start YOUR_LINK_CODE
- After the bot confirms linking, the Telegram account is attached to that internal user.
Supported Commands
-
/start LINK_CODECompletes Telegram linking. -
/statusReturns the health summary for active servers visible to the linked user. -
/servicesReturns managed services across active servers. -
/services SERVER_NAMEReturns managed services for a specific server. -
/restart SERVER_NAME SERVICE_NAMEQueues a restart action for linked users with roleadminoroperator.
API Endpoints
User-facing:
GET /api/v1/telegram/statusPOST /api/v1/telegram/linkGET /api/v1/telegram/link/meDELETE /api/v1/telegram/link/{link_id}POST /api/v1/telegram/test-message
Bot/internal:
POST /api/v1/telegram/bot/link/completePOST /api/v1/telegram/bot/statusPOST /api/v1/telegram/bot/servicesPOST /api/v1/telegram/bot/restart
The bot/internal endpoints are protected by X-Telegram-Bot-Secret.
How To Run
For local development:
- Set
TELEGRAM_BOT_TOKENandTELEGRAM_BOT_API_SECRETin.env. - Start the stack:
docker compose up --build
- Request a link code through the backend API.
- Complete the link in Telegram with
/start LINK_CODE. - Verify
/statusand/services.
How To Verify
POST /api/v1/telegram/linkreturns alink_code./start LINK_CODEin Telegram succeeds.GET /api/v1/telegram/link/meshows the linked chat.POST /api/v1/telegram/test-messagereturns success./restart SERVER_NAME SERVICE_NAMEcreates an action and audit entry withactor_source="telegram".