Files
ltlnotifyer/start.py
Alexey Sokolov 182871a0a2 added start.py
2022-02-09 18:21:55 +03:00

46 lines
1.1 KiB
Python

import logging
from aiogram import Bot, Dispatcher
from aiogram.dispatcher.webhook import configure_app
from aiogram.contrib.middlewares.logging import LoggingMiddleware
from aiohttp import web
from config import config
WEBAPP_PORT = 3001
TELEGRAM_WEBHOOK_URL = f'{config.base_url}{config.api_token}'
logging.basicConfig(level=logging.INFO)
bot = Bot(token=config.TELEGRAM_TOKEN)
dp = Dispatcher(bot)
dp.middleware.setup(LoggingMiddleware())
async def test_route(_):
return web.json_response({'test': 'passed'}, status=200)
async def on_startup(_):
await bot.set_webhook(TELEGRAM_WEBHOOK_URL)
async def on_shutdown(_):
logging.warning('Shutting down')
await bot.delete_webhook()
await dp.storage.close()
await dp.storage.wait_closed()
await bot.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(dp, app, '/'+config.api_token)
if __name__ == '__main__':
web.run_app(app, port=WEBAPP_PORT)