Sadeep Sachintha commited on
Commit ·
e4759e7
1
Parent(s): f370663
feat: add optional custom Telegram Bot API server proxy/mirror configuration
Browse files- core/config.py +1 -0
- main.py +8 -2
core/config.py
CHANGED
|
@@ -5,6 +5,7 @@ from typing import Optional
|
|
| 5 |
class Settings(BaseSettings):
|
| 6 |
bot_token: str = ""
|
| 7 |
webhook_url: Optional[str] = None
|
|
|
|
| 8 |
fx_api_key: str = ""
|
| 9 |
database_url: str = "sqlite+aiosqlite:///./flyrates.db"
|
| 10 |
log_level: str = "INFO"
|
|
|
|
| 5 |
class Settings(BaseSettings):
|
| 6 |
bot_token: str = ""
|
| 7 |
webhook_url: Optional[str] = None
|
| 8 |
+
telegram_api_server: Optional[str] = None
|
| 9 |
fx_api_key: str = ""
|
| 10 |
database_url: str = "sqlite+aiosqlite:///./flyrates.db"
|
| 11 |
log_level: str = "INFO"
|
main.py
CHANGED
|
@@ -6,6 +6,7 @@ from fastapi import FastAPI, Request, Response
|
|
| 6 |
from fastapi.staticfiles import StaticFiles
|
| 7 |
from fastapi.responses import FileResponse
|
| 8 |
from aiogram import Bot, Dispatcher, types
|
|
|
|
| 9 |
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
| 10 |
from sqlalchemy import select, func
|
| 11 |
|
|
@@ -35,8 +36,13 @@ logger = logging.getLogger(__name__)
|
|
| 35 |
# Global diagnostic results storage
|
| 36 |
diagnostic_results = []
|
| 37 |
|
| 38 |
-
# Initialize Aiogram Bot
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
dp = Dispatcher()
|
| 41 |
dp.include_router(bot_router)
|
| 42 |
|
|
|
|
| 6 |
from fastapi.staticfiles import StaticFiles
|
| 7 |
from fastapi.responses import FileResponse
|
| 8 |
from aiogram import Bot, Dispatcher, types
|
| 9 |
+
from aiogram.client.telegram import TelegramAPIServer
|
| 10 |
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
| 11 |
from sqlalchemy import select, func
|
| 12 |
|
|
|
|
| 36 |
# Global diagnostic results storage
|
| 37 |
diagnostic_results = []
|
| 38 |
|
| 39 |
+
# Initialize Aiogram Bot (with custom reverse proxy API server if configured)
|
| 40 |
+
if settings.telegram_api_server:
|
| 41 |
+
api_server = TelegramAPIServer.from_base(settings.telegram_api_server)
|
| 42 |
+
bot = Bot(token=settings.bot_token, api=api_server)
|
| 43 |
+
logger.info(f"Initialized Bot with custom API server: {settings.telegram_api_server}")
|
| 44 |
+
else:
|
| 45 |
+
bot = Bot(token=settings.bot_token)
|
| 46 |
dp = Dispatcher()
|
| 47 |
dp.include_router(bot_router)
|
| 48 |
|