-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwebhook.py
57 lines (38 loc) · 1.29 KB
/
webhook.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import logging
from aiogram import Dispatcher
from aiogram.utils.executor import start_webhook
from bot.commands import set_default_commands
from loader import dp, bot, config
from utils.misc.logging import logger
logging.basicConfig(level=logging.INFO)
WEBHOOK_HOST = config.WEBHOOK_HOST
WEBHOOK_PATH = config.WEBHOOK_PATH
WEBHOOK_URL = f'{WEBHOOK_HOST}{WEBHOOK_PATH}'
WEBAPP_HOST = '0.0.0.0'
WEBAPP_PORT = config.WEBHOOK_PORT
async def on_startup(dispatcher: Dispatcher):
logger.info('Bot startup')
logger.info(f'{WEBHOOK_URL=}')
await bot.set_webhook(WEBHOOK_URL)
for admin_id in config.ADMINS:
await bot.send_message(admin_id, 'Бот успешно запущен')
await set_default_commands()
async def on_shutdown(dispatcher: Dispatcher):
logger.warning('Shutting down..')
await bot.delete_webhook()
await dp.storage.close()
await dp.storage.wait_closed()
logger.warning('Bye!')
if __name__ == '__main__':
from bot.middlewares import setup_middleware
from bot import filters, handlers
setup_middleware(dp)
start_webhook(
dispatcher=dp,
webhook_path=WEBHOOK_PATH,
on_startup=on_startup,
on_shutdown=on_shutdown,
skip_updates=True,
host=WEBAPP_HOST,
port=WEBAPP_PORT,
)