Update WebApp
This commit is contained in:
16
main.py
16
main.py
@@ -69,7 +69,7 @@ async def main():
|
||||
from server import app as web_app
|
||||
import uvicorn
|
||||
web_app.state.bot = bot
|
||||
config = uvicorn.Config(web_app, host="0.0.0.0", port=8000, log_level="info")
|
||||
config = uvicorn.Config(web_app, host="0.0.0.0", port=CONFIG["WEB_APP_PORT"], log_level="info")
|
||||
server = uvicorn.Server(config)
|
||||
except ImportError:
|
||||
logger.error("Could not import server or uvicorn")
|
||||
@@ -80,19 +80,25 @@ async def main():
|
||||
|
||||
# Set Menu Button
|
||||
from aiogram.types import MenuButtonWebApp, WebAppInfo
|
||||
if CONFIG["BASE_URL"]:
|
||||
if CONFIG["WEB_APP_URL"]:
|
||||
try:
|
||||
await bot.set_chat_menu_button(
|
||||
menu_button=MenuButtonWebApp(text="🚀 Dashboard", web_app=WebAppInfo(url=CONFIG["BASE_URL"]))
|
||||
menu_button=MenuButtonWebApp(text="🚀 Dashboard", web_app=WebAppInfo(url=CONFIG["WEB_APP_URL"]))
|
||||
)
|
||||
logger.info(f"Menu button set to {CONFIG['BASE_URL']}")
|
||||
logger.info(f"Menu button set to {CONFIG['WEB_APP_URL']}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to set menu button: {e}")
|
||||
else:
|
||||
# Если URL не задан, сбрасываем кнопку (чтобы не осталась старая ссылка)
|
||||
await bot.delete_chat_menu_button()
|
||||
logger.info("WEB_APP_URL not found, menu button reset to default.")
|
||||
|
||||
logger.info(f"Config: BASE_URL={CONFIG['BASE_URL']}, WEB_APP_URL={CONFIG['WEB_APP_URL']}")
|
||||
|
||||
logger.info("Bot started!")
|
||||
|
||||
if server:
|
||||
logger.info("Starting Web App on port 8000")
|
||||
logger.info(f"Starting Web App on port {CONFIG['WEB_APP_PORT']}")
|
||||
await asyncio.gather(
|
||||
dp.start_polling(bot),
|
||||
server.serve()
|
||||
|
||||
Reference in New Issue
Block a user