From 24891577287c759813899f0b12b124517610799b Mon Sep 17 00:00:00 2001 From: Dmitry Afanasyev Date: Tue, 16 Aug 2022 23:34:14 +0300 Subject: [PATCH] webhook url with token --- app/main.py | 17 +++++++++-------- app/settings.py | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/main.py b/app/main.py index 2fb3091..3cf6727 100644 --- a/app/main.py +++ b/app/main.py @@ -7,7 +7,14 @@ from aiohttp import web from app.core.bot import bot, dispatcher from app.core.logger import logger from app.core.scheduler import asyncio_schedule -from app.settings import START_WITH_WEBHOOK, WEBAPP_HOST, WEBAPP_PORT, WEBHOOK_URL +from app.settings import ( + API_TOKEN, + START_WITH_WEBHOOK, + WEBAPP_HOST, + WEBAPP_PORT, + WEBHOOK_PATH, + WEBHOOK_URL, +) async def bot_startup() -> None: @@ -75,15 +82,9 @@ async def webhook(request: web.Request) -> web.Response: return web.Response(status=HTTPStatus.OK) -async def hello_world(request: web.Request) -> web.Response: - logger.info(request) - return web.Response(body='Hello World') - - async def create_app() -> web.Application: application = web.Application() - application.router.add_post('/', webhook) - application.router.add_post('/hello', hello_world) + application.router.add_post(f'/{WEBHOOK_PATH}/{API_TOKEN}', webhook) application.on_startup.append(on_startup_gunicorn) application.on_shutdown.append(on_shutdown_gunicorn) return application diff --git a/app/settings.py b/app/settings.py index 3216476..4a38218 100644 --- a/app/settings.py +++ b/app/settings.py @@ -20,7 +20,7 @@ API_TOKEN = config('API_TOKEN', default='123456789:AABBCCDDEEFFaabbccddeeff-1234 # webhook settings WEBHOOK_HOST = config('WEBHOOK_HOST', default='') WEBHOOK_PATH = config('WEBHOOK_PATH', default='') -WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}" +WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}/{API_TOKEN}" # webserver settings WEBAPP_HOST = config('WEBAPP_HOST', default='127.0.0.1') # or ip