move webhook auth key to bot config
All checks were successful
Build Docs / changes (push) Successful in 5s
Build Docs / build-docs (push) Has been skipped
Build Docs / deploy-docs (push) Has been skipped

This commit is contained in:
Alexander Kalinovsky
2025-04-12 17:07:39 +07:00
parent 783ecac91a
commit c81fb57c1a
3 changed files with 4 additions and 8 deletions

View File

@@ -21,7 +21,7 @@ async def telegram_webhook(
app: QBotApp = request.app
request_token = request.headers.get("X-Telegram-Bot-Api-Secret-Token")
if request_token != app.bot_auth_token:
if request_token != app.config.TELEGRAM_WEBHOOK_AUTH_KEY:
logger.warning("Unauthorized request %s", request)
return Response(status_code=403)
try:

View File

@@ -47,6 +47,8 @@ class Config(BaseSettings):
else ''
}"
TELEGRAM_WEBHOOK_AUTH_KEY: str = "changethis"
TELEGRAM_BOT_USERNAME: str = "quickbot"
TELEGRAM_BOT_SERVER: str = "https://api.telegram.org"
TELEGRAM_BOT_SERVER_IS_LOCAL: bool = False
@@ -54,10 +56,6 @@ class Config(BaseSettings):
ADMIN_TELEGRAM_ID: int
USE_NGROK: bool = False
NGROK_AUTH_TOKEN: str = "changethis"
NGROK_URL: str = ""
LOG_LEVEL: str = "DEBUG"
def _check_default_secret(self, var_name: str, value: str | None) -> None:

View File

@@ -123,8 +123,6 @@ class QBotApp(Generic[UserType, ConfigType], FastAPI):
self.dp = dp
self.bot_auth_token = token_hex(128)
self.start_handler = bot_start
self.bot_commands = dict[str, BotCommand]()
@@ -174,7 +172,7 @@ class QBotApp(Generic[UserType, ConfigType], FastAPI):
url=f"{self.config.TELEGRAM_WEBHOOK_URL}/telegram/webhook",
drop_pending_updates=True,
allowed_updates=self.allowed_updates,
secret_token=self.bot_auth_token,
secret_token=self.webhook_auth_key,
)
async def show_form(