diff --git a/middlewares/webhook_guard.py b/middlewares/webhook_guard.py index 88155d22..8919e40c 100644 --- a/middlewares/webhook_guard.py +++ b/middlewares/webhook_guard.py @@ -2,9 +2,20 @@ from aiohttp import web def telegram_webhook_guard_middleware(webhook_path: str, secret_token: str): + webhook_path = (webhook_path or "").strip() + if not webhook_path.startswith("/"): + webhook_path = "/" + webhook_path + + if webhook_path != "/" and webhook_path.endswith("/"): + webhook_path = webhook_path.rstrip("/") + @web.middleware async def middleware(request: web.Request, handler): - if request.path != webhook_path: + request_path = request.rel_url.path + if request_path != "/" and request_path.endswith("/"): + request_path = request_path.rstrip("/") + + if request_path != webhook_path: return await handler(request) if request.method != "POST":