From a183122e8c058ce97217d760c124f436f327e692 Mon Sep 17 00:00:00 2001 From: dementiev27 <56401662+dementiev27@users.noreply.github.com> Date: Sat, 8 Aug 2020 18:48:34 +0300 Subject: [PATCH] Custom routes to Aiohttp web server. Added opportunity to add custom routes to Aiohttp web server while setting webhook. Edited `start_webhook` method, now it takes `custom_routes` parameter (nested list of lists, e.g.: `[['GET', '/path', handler], ['POST', '/path2', handler_2]]`). --- aiogram/utils/executor.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/aiogram/utils/executor.py b/aiogram/utils/executor.py index fe3483f6..9c9a9760 100644 --- a/aiogram/utils/executor.py +++ b/aiogram/utils/executor.py @@ -69,9 +69,9 @@ def set_webhook(dispatcher: Dispatcher, webhook_path: str, *, loop: Optional[asy return executor -def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None, - on_startup=None, on_shutdown=None, check_ip=False, retry_after=None, route_name=DEFAULT_ROUTE_NAME, - **kwargs): +def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None, on_startup=None, on_shutdown=None, + check_ip=False, retry_after=None, route_name=DEFAULT_ROUTE_NAME, + custom_routes: List[List[Union[str, str, Coroutine[Any, Any, Response]]]] = None, **kwargs): """ Start bot in webhook mode @@ -83,6 +83,7 @@ def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None, :param on_shutdown: :param check_ip: :param route_name: + :param custom_routes: :param kwargs: :return: """ @@ -95,8 +96,12 @@ def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None, check_ip=check_ip, retry_after=retry_after, route_name=route_name) - executor.run_app(**kwargs) + if custom_routes != None: + for route in custom_routes: + executor.web_app.router.add_route(*route) + + executor.run_app(**kwargs) def start(dispatcher, future, *, loop=None, skip_updates=None, on_startup=None, on_shutdown=None):