intra_max_chatbot/main.py

59 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import asyncio
import uvicorn
from bot.logging_setup import setup_logging
setup_logging() # до всех остальных импортов
from database.connection import init_db
from bot.setup import create_bot_and_dispatcher
from bot.notifier import run_notifier
from admin.app import create_admin_app
from maxapi.types.command import BotCommand
import config
async def main() -> None:
if config.DRY_RUN:
print(
"\n" + "=" * 60 + "\n"
" ⚠️ DRY-RUN режим активен\n"
" Записи в Intradesk API выполняться НЕ будут.\n"
" Payload запросов будет выводиться в консоль.\n"
+ "=" * 60 + "\n"
)
await init_db()
bot, dp = create_bot_and_dispatcher()
# Регистрируем команды — появляются в меню кнопки "/" в поле ввода
try:
await bot.set_my_commands(
BotCommand(name="start", description="Главное меню"),
BotCommand(name="menu", description="Показать меню"),
BotCommand(name="cancel", description="Отменить текущее действие"),
)
except Exception as e:
import logging
logging.getLogger(__name__).warning("set_my_commands failed: %s", e)
admin_app = create_admin_app()
server = uvicorn.Server(
uvicorn.Config(
admin_app,
host=config.ADMIN_HOST,
port=config.ADMIN_PORT,
log_level="info",
)
)
await asyncio.gather(
dp.start_polling(bot, skip_updates=True),
server.serve(),
run_notifier(bot),
)
if __name__ == "__main__":
asyncio.run(main())