Files
ltlnotifyer/web/__init__.py
2022-02-10 17:21:47 +03:00

35 lines
889 B
Python

import logging
from aiogram.dispatcher.webhook import configure_app
from aiohttp import web
from config import config
from telegram import telegram_bot, telegram_dispatcher
from .routes import routes, TELEGRAM_WEBHOOK_ROUTE
TELEGRAM_WEBHOOK_URL = f'{config.base_url}{TELEGRAM_WEBHOOK_ROUTE}'
async def on_startup(_):
await telegram_bot.set_webhook(TELEGRAM_WEBHOOK_URL)
async def on_shutdown(_):
logging.warning('Shutting down')
await telegram_bot.delete_webhook()
await telegram_dispatcher.storage.close()
await telegram_dispatcher.storage.wait_closed()
session = await telegram_bot.get_session()
await session.close()
logging.warning('Bye!..')
app = web.Application()
app.add_routes(routes)
app.on_startup.append(on_startup)
app.on_shutdown.append(on_shutdown)
configure_app(telegram_dispatcher, app, TELEGRAM_WEBHOOK_ROUTE)
__all__ = ('app',)