Files
ltlnotifyer/start.py
2022-02-10 15:56:57 +03:00

41 lines
1.0 KiB
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
WEBAPP_PORT = 3001
TELEGRAM_WEBHOOK_URL = f'{config.base_url}/{config.teletoken}'
logging.basicConfig(level=logging.INFO)
async def test_route(_):
return web.json_response({'test': 'passed'}, status=200)
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([web.get('/test', test_route)])
app.on_startup.append(on_startup)
app.on_shutdown.append(on_shutdown)
configure_app(telegram_dispatcher, app, '/'+config.teletoken)
if __name__ == '__main__':
web.run_app(app, port=WEBAPP_PORT)