diff --git a/src/qbot/config/__init__.py b/src/qbot/config/__init__.py index c4263af..7496072 100644 --- a/src/qbot/config/__init__.py +++ b/src/qbot/config/__init__.py @@ -26,7 +26,27 @@ class Config(BaseSettings): API_PORT: int = 8000 - TELEGRAM_WEBHOOK_URL: str = "http://localhost:8000" + TELEGRAM_WEBHOOK_DOMAIN: str = "localhost" + TELEGRAM_WEBHOOK_SHEME: str = "https" + TELEGRAM_WEBHOOK_PORT: int = 443 + + @property + def TELEGRAM_WEBHOOK_URL(self) -> str: + return f"{self.TELEGRAM_WEBHOOK_SHEME}://{self.TELEGRAM_WEBHOOK_DOMAIN}{ + f':{self.TELEGRAM_WEBHOOK_PORT}' + if ( + ( + self.TELEGRAM_WEBHOOK_PORT != 80 + and self.TELEGRAM_WEBHOOK_SHEME == 'http' + ) + or ( + self.TELEGRAM_WEBHOOK_PORT != 443 + and self.TELEGRAM_WEBHOOK_SHEME == 'https' + ) + ) + else '' + }" + TELEGRAM_BOT_SERVER: str = "https://api.telegram.org" TELEGRAM_BOT_SERVER_IS_LOCAL: bool = False TELEGRAM_BOT_TOKEN: str = "changethis" diff --git a/src/qbot/main.py b/src/qbot/main.py index d958db0..00979d9 100644 --- a/src/qbot/main.py +++ b/src/qbot/main.py @@ -1,4 +1,3 @@ -from asyncio import sleep from contextlib import asynccontextmanager from typing import Callable, Any from aiogram import Bot, Dispatcher @@ -196,11 +195,11 @@ class QBotApp[UserType: UserBase](FastAPI): ) await self.bot.set_webhook( - url=f"{self.config.TELEGRAM_WEBHOOK_URL}/telegram/webhook", - drop_pending_updates=True, - allowed_updates=self.allowed_updates, - secret_token=self.bot_auth_token, - ) + url=f"{self.config.TELEGRAM_WEBHOOK_URL}/telegram/webhook", + drop_pending_updates=True, + allowed_updates=self.allowed_updates, + secret_token=self.bot_auth_token, + ) async def bot_close(self): await self.bot.delete_webhook()