From 0873cdb16d9d9d5dcb5490bb675c785dc16eb2e5 Mon Sep 17 00:00:00 2001 From: Vladless Date: Fri, 6 Feb 2026 00:17:24 +0300 Subject: [PATCH] avoid 204 responses for non-telegram webhooks --- middlewares/webhook_guard.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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":