avoid 204 responses for non-telegram webhooks

This commit is contained in:
Vladless
2026-02-06 00:17:24 +03:00
parent 0265e9cb50
commit 0873cdb16d
+12 -1
View File
@@ -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":