ЗАпускаю бота через вебхуки бот запускается овтечает минуту и выключается
логи пустые что делать ? вот файл bot.py
import asyncio
import logging
import os
import gspread_asyncio
import openai
import pytz
from aiogram import Bot, Dispatcher
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.utils.executor import start_webhook
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from tg_bot.config import load_config
from tg_bot.db.postgresql import Database
from tg_bot.db.sheets import get_ready_vals
from tg_bot.handlers.first_interaction import register_first_interaction_handlers
from tg_bot.handlers.menu_handlers import register_menu_handlers
from tg_bot.handlers.push_handlers import register_push_handlers
from tg_bot.handlers.system_handlers import register_system_handlers
from tg_bot.handlers.task_board_handlers import register_task_board_handlers
from tg_bot.middlewares.scheduler import SchedulerMiddleware
from tg_bot.misc.pushes import schedule_pushes
logger = logging.getLogger(__name__)
def register_all_middlewares(dp: Dispatcher, scheduler: AsyncIOScheduler):
dp.setup_middleware(SchedulerMiddleware(scheduler))
def register_all_filters(dp: Dispatcher):
pass
def register_all_handlers(dp: Dispatcher):
register_system_handlers(dp)
register_task_board_handlers(dp)
register_menu_handlers(dp)
register_push_handlers(dp)
register_first_interaction_handlers(dp)
# register_registration_handlers(dp
try:
config = load_config('tg_bot/.env')
except FileNotFoundError:
config = load_config('/home/andreisiradze/AI-life-coach/tg_bot/.env')
# init bot
bot = Bot(token=config.tg_bot.token, parse_mode='html') # инициализация бота
openai.api_key = config.ai.ai_token # задаем апи ключ для openai
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
db = Database()
scheduler = AsyncIOScheduler() # Инстанс скеджулера
scheduler.timezone = pytz.timezone('Asia/Tbilisi')
scheduler.start()
WEBHOOK_HOST = f"https://appolo-life-coach.onrender.com"
WEBHOOK_PATH = f"/webhook/{os.getenv('BOT_TOKEN')}"
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
# WEB APP SETTINGS
WEBAPP_HOST = '0.0.0.0'
WEBAPP_PORT = '8080'
async def on_shutdown(dp):
logging.warning('Shutting down..')
# insert code here to run it before shutdown
# Remove webhook (not acceptable in some cases)
await bot.delete_webhook()
# Close DB connection (if used)
await dp.storage.close()
await dp.storage.wait_closed()
async def on_startup(dp):
await bot.set_webhook(WEBHOOK_URL)
###
google_client_manager = gspread_asyncio.AsyncioGspreadClientManager( # подключаем таблицы
config.misc.scoped_credentials
)
google_client_manager = await google_client_manager.authorize()
ready_vals = await get_ready_vals(google_client_manager) # Получаем текстовые значения
# Загружаем текстовые значения в бота
bot['text'] = ready_vals[0]
bot['prompts'] = ready_vals[1]
bot['daily'] = ready_vals[2]
bot['config'] = config # сохраняем конфиг в переменную бота
bot['google_client_manager'] = google_client_manager # сохраняем в переменную бота клиент таблиц
bot['db'] = db
bot['dp'] = dp
bot['scheduler'] = scheduler
bot['storage'] = storage
await db.create(
db=config.db
)
await schedule_pushes(db=db, scheduler=scheduler, bot=bot, storage=storage)
logging.info(f"bot is running")
# insert code here to run it after start
logging.basicConfig(
level=logging.DEBUG,
format=u'%(filename)s:%(lineno)d #%(levelname)-8s [%(asctime)s] - %(message)s',
)
register_all_middlewares(dp, scheduler)
register_all_filters(dp)
register_all_handlers(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
)