diff --git a/.claude/commands/validate.md b/.claude/commands/validate.md index 4c7bfc8..32be45b 100644 --- a/.claude/commands/validate.md +++ b/.claude/commands/validate.md @@ -401,9 +401,9 @@ else exit 1 fi -# Telegram Bot health check -if check_port_available 8002; then - echo "✅ Telegram bot internal API is running on port 8002" +# Telegram Bot health check (now part of main backend on port 8000) +if curl -s http://localhost:8000/api/telegram/health > /dev/null 2>&1; then + echo "✅ Telegram bot is running (via main backend)" else echo "⚠️ Telegram bot is not running (optional for validation)" fi diff --git a/backend/.env.dev.example b/backend/.env.dev.example index b6c5700..ab3dbfe 100644 --- a/backend/.env.dev.example +++ b/backend/.env.dev.example @@ -143,7 +143,7 @@ TELEGRAM_BOT_TOKEN=your_bot_token_from_botfather BACKEND_URL=http://localhost:8000 # Internal API port (bot's internal API for backend callbacks) -INTERNAL_API_PORT=8002 +# INTERNAL_API_PORT=8002 # DEPRECATED: Now served via main app at /api/telegram/internal/* # Enable internal API documentation (development only) ENABLE_DOCS=false diff --git a/backend/.env.prod.example b/backend/.env.prod.example index 9a8c1ef..c294bbe 100644 --- a/backend/.env.prod.example +++ b/backend/.env.prod.example @@ -137,7 +137,7 @@ TELEGRAM_BOT_TOKEN=your_bot_token_from_botfather BACKEND_URL=http://localhost:8000 # Internal API port (bot's internal API for backend callbacks) -INTERNAL_API_PORT=8002 +# INTERNAL_API_PORT=8002 # DEPRECATED: Now served via main app at /api/telegram/internal/* # Enable internal API documentation (DISABLE in production!) ENABLE_DOCS=false diff --git a/backend/.env.test.example b/backend/.env.test.example index dab39e5..e375ee0 100644 --- a/backend/.env.test.example +++ b/backend/.env.test.example @@ -144,7 +144,7 @@ TELEGRAM_BOT_TOKEN=8483383555:AAGNY1z6WiBkvVfy1ZV_gM_JnAqW4q4MlEY BACKEND_URL=http://localhost:8000 # Internal API port (bot's internal API for backend callbacks) -INTERNAL_API_PORT=8002 +# INTERNAL_API_PORT=8002 # DEPRECATED: Now served via main app at /api/telegram/internal/* # Enable internal API documentation (development only) ENABLE_DOCS=false diff --git a/backend/modules/telegram/bot_main.py b/backend/modules/telegram/bot_main.py index 8472bac..46b6161 100644 --- a/backend/modules/telegram/bot_main.py +++ b/backend/modules/telegram/bot_main.py @@ -10,8 +10,7 @@ import logging import os from pathlib import Path from dotenv import load_dotenv -import uvicorn -from threading import Thread +# Note: uvicorn and threading removed - internal API now served via main.py # ============================================================================ # LOAD ENVIRONMENT VARIABLES FIRST - BEFORE ANY APP IMPORTS @@ -69,8 +68,7 @@ from backend.modules.telegram.bot.handlers import ( # Import email authentication handler from backend.modules.telegram.bot.email_handlers import email_login_handler -# Import internal API -from backend.modules.telegram.internal_api import internal_api +# Note: internal_api import removed - now served via main.py at /api/telegram/internal/* # Configure logging logging.basicConfig( @@ -82,7 +80,7 @@ logger = logging.getLogger(__name__) # Environment variables (already loaded above) TELEGRAM_BOT_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN') BACKEND_URL = os.getenv('BACKEND_URL', 'http://localhost:8000') -INTERNAL_API_PORT = int(os.getenv('INTERNAL_API_PORT', '8002')) +# Note: INTERNAL_API_PORT removed - internal API now served via main.py # ============================================================================ @@ -153,29 +151,10 @@ def create_telegram_application() -> Application: return application -# ============================================================================ -# INTERNAL API SERVER -# ============================================================================ - -def run_internal_api(): - """ - Run the internal FastAPI server in a separate thread. - - This API handles communication from the backend (saving auth codes). - """ - logger.info(f"Starting internal API on port {INTERNAL_API_PORT}...") - - uvicorn.run( - internal_api, - host="0.0.0.0", - port=INTERNAL_API_PORT, - log_level="info" - ) - - # ============================================================================ # STARTUP/SHUTDOWN # ============================================================================ +# Note: Internal API server removed - now served via main.py at /api/telegram/internal/* async def startup(): """ @@ -247,10 +226,7 @@ async def main(): # Create Telegram application telegram_app = create_telegram_application() - # Start internal API in a separate thread - api_thread = Thread(target=run_internal_api, daemon=True) - api_thread.start() - logger.info(f"✅ Internal API started on port {INTERNAL_API_PORT}") + # Note: Internal API server removed - now served via main.py # Start scheduled cleanup task in background cleanup_task = asyncio.create_task(scheduled_cleanup()) diff --git a/data/ocr_queue/.gitkeep b/data/ocr_queue/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/data/ocr_queue/files/.gitkeep b/data/ocr_queue/files/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/deployment/windows/docs/TELEGRAM_BOT_DEPLOYMENT.md b/deployment/windows/docs/TELEGRAM_BOT_DEPLOYMENT.md index d70e714..fe44cfa 100644 --- a/deployment/windows/docs/TELEGRAM_BOT_DEPLOYMENT.md +++ b/deployment/windows/docs/TELEGRAM_BOT_DEPLOYMENT.md @@ -1,9 +1,20 @@ # ROA2WEB Telegram Bot - Windows Server Deployment Guide +> ⚠️ **DEPRECATED ARCHITECTURE** +> +> This documentation refers to the OLD microservices architecture where the Telegram bot +> ran as a separate service on port 8002. The current architecture is an **ultrathin monolith** +> where everything runs on a single port (8000/8001) via `backend/main.py`. +> +> **Current Architecture**: Telegram bot runs as a background task within the unified backend. +> Internal API endpoints are now at `/api/telegram/internal/*` on the main port. +> +> See `CLAUDE.md` and `QUICK-START.md` for the current architecture. + **Target Server**: Windows Server (10.0.20.36) **Deployment Method**: Windows Service (NSSM) - No Docker **Service Name**: ROA2WEB-TelegramBot -**Internal API Port**: 8002 +**Internal API Port**: ~~8002~~ (DEPRECATED - now via main backend) **Created**: 2025-10-22 **Last Updated**: 2025-10-22 diff --git a/deployment/windows/docs/TELEGRAM_BOT_TROUBLESHOOTING.md b/deployment/windows/docs/TELEGRAM_BOT_TROUBLESHOOTING.md index 6f06f4c..20b642f 100644 --- a/deployment/windows/docs/TELEGRAM_BOT_TROUBLESHOOTING.md +++ b/deployment/windows/docs/TELEGRAM_BOT_TROUBLESHOOTING.md @@ -1,5 +1,11 @@ # ROA2WEB Telegram Bot - Windows Deployment Troubleshooting Guide +> ⚠️ **DEPRECATED ARCHITECTURE** +> +> This documentation refers to the OLD microservices architecture (port 8002). +> The current architecture is an **ultrathin monolith** - everything on port 8000/8001. +> Telegram internal API is now at `/api/telegram/internal/*` on the main backend. + This guide helps diagnose and fix common issues with Telegram bot integration on Windows Server deployments. ## Problem: "Link invalid sau expirat" (Invalid or expired link) diff --git a/docs/telegram/README.md b/docs/telegram/README.md index 2792593..4dba540 100644 --- a/docs/telegram/README.md +++ b/docs/telegram/README.md @@ -1,5 +1,12 @@ # ROA2WEB Telegram Bot +> ⚠️ **ARCHITECTURE NOTE** +> +> This documentation partially references the old standalone bot architecture. +> The current architecture is an **ultrathin monolith** where the Telegram bot runs +> as a background task within the main backend (`backend/main.py`) on port 8000/8001. +> The `INTERNAL_API_PORT` variable is no longer used - internal API is at `/api/telegram/internal/*`. + > **Telegram Frontend for ROA2WEB ERP System** with Direct Command Interface ## Overview @@ -117,8 +124,8 @@ BACKEND_URL=http://localhost:8001 # Database SQLITE_DB_PATH=./data/telegram_bot.db -# Internal API (for backend communication) -INTERNAL_API_PORT=8002 +# Internal API - DEPRECATED (now served via main backend at /api/telegram/internal/*) +# INTERNAL_API_PORT=8002 # Optional LOG_LEVEL=INFO diff --git a/docs/telegram/testing/DOCKER_TESTING_GUIDE.md b/docs/telegram/testing/DOCKER_TESTING_GUIDE.md index 06259d8..d634157 100644 --- a/docs/telegram/testing/DOCKER_TESTING_GUIDE.md +++ b/docs/telegram/testing/DOCKER_TESTING_GUIDE.md @@ -1,5 +1,11 @@ # 🐳 Docker Testing Guide - ROA2WEB Telegram Bot +> ⚠️ **DEPRECATED ARCHITECTURE** +> +> This guide references the OLD microservices architecture (separate Telegram container on port 8002). +> The current architecture is an **ultrathin monolith** where the Telegram bot runs as a background +> task within the main backend (port 8000/8001). No separate Docker container needed for Telegram. + This guide provides instructions for testing the Telegram bot Docker deployment. ## 📋 Prerequisites diff --git a/src/config/menu.js b/src/config/menu.js index a6e01ff..c93a0ac 100644 --- a/src/config/menu.js +++ b/src/config/menu.js @@ -20,7 +20,8 @@ export const menuSections = [ items: [ { to: '/reports/telegram', icon: 'pi pi-telegram', label: 'Telegram Bot' }, { to: '/reports/cache-stats', icon: 'pi pi-chart-bar', label: 'Statistici Cache' }, - { to: '/data-entry/ocr-metrics', icon: 'pi pi-eye', label: 'Statistici OCR' } + { to: '/data-entry/ocr-metrics', icon: 'pi pi-eye', label: 'Statistici OCR' }, + { to: '/reports/server-logs', icon: 'pi pi-server', label: 'Server Logs' } ] } ] diff --git a/src/modules/reports/views/ServerLogsView.vue b/src/modules/reports/views/ServerLogsView.vue index 04c899a..afa01ea 100644 --- a/src/modules/reports/views/ServerLogsView.vue +++ b/src/modules/reports/views/ServerLogsView.vue @@ -70,7 +70,11 @@
No log entries found
{{ line }}
+ {{ line }}