-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_aiogram.py
41 lines (33 loc) · 1.33 KB
/
main_aiogram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from aiogram import Dispatcher, executor
from aiogram.contrib.middlewares.logging import LoggingMiddleware
from logfmt_logger import getLogger
from cost_my_chemo_bot.bots.telegram.bot import close_bot, init_bot, make_bot
from cost_my_chemo_bot.bots.telegram.dispatcher import make_dispatcher
from cost_my_chemo_bot.bots.telegram.storage import make_storage
from cost_my_chemo_bot.config import SETTINGS, WEBHOOK_SETTINGS, BotMode
logger = getLogger(__name__)
async def on_startup(dp: Dispatcher):
await init_bot(bot=dp.bot, dp=dp)
async def on_shutdown(dp):
await close_bot(bot=dp.bot, dp=dp)
if __name__ == "__main__":
# Configure logging
getLogger("aiogram", level=SETTINGS.LOG_LEVEL)
bot = make_bot()
storage = make_storage()
dp = make_dispatcher(bot, storage=storage)
dp.middleware.setup(LoggingMiddleware())
if SETTINGS.BOT_MODE is BotMode.POLLING:
executor.start_polling(
dp, skip_updates=True, on_startup=on_startup, on_shutdown=on_shutdown
)
elif SETTINGS.BOT_MODE is BotMode.WEBHOOK:
executor.start_webhook(
dp,
webhook_path=WEBHOOK_SETTINGS.WEBHOOK_PATH,
skip_updates=True,
on_startup=on_startup,
on_shutdown=on_shutdown,
host=WEBHOOK_SETTINGS.HOST,
port=WEBHOOK_SETTINGS.PORT,
)