feat: allow /start description and keep menu default

This commit is contained in:
Machka Pasla
2025-07-04 22:35:13 +07:00
parent ea50567a42
commit d1d701bff3
4 changed files with 17 additions and 5 deletions
+1
View File
@@ -17,6 +17,7 @@ SUPPORT_LINK=https://t.me/your_support_link
SERVER_STATUS_URL=https://status.yourdomain.tld/status/your_service SERVER_STATUS_URL=https://status.yourdomain.tld/status/your_service
TERMS_OF_SERVICE_URL=https://example.com/tos TERMS_OF_SERVICE_URL=https://example.com/tos
SUBSCRIPTION_MINI_APP_URL= SUBSCRIPTION_MINI_APP_URL=
START_COMMAND_DESCRIPTION=
# YooKassa Payment Gateway Configuration # YooKassa Payment Gateway Configuration
YOOKASSA_SHOP_ID=your_shop_id YOOKASSA_SHOP_ID=your_shop_id
+1
View File
@@ -84,6 +84,7 @@ This Telegram bot is designed to automate the sale and management of subscriptio
* `SUPPORT_LINK`: (Optional) URL for a support chat/contact (e.g., `https://t.me/your_support`). * `SUPPORT_LINK`: (Optional) URL for a support chat/contact (e.g., `https://t.me/your_support`).
* `SERVER_STATUS_URL`: (Optional) URL to a server status page (e.g., Uptime Kuma). * `SERVER_STATUS_URL`: (Optional) URL to a server status page (e.g., Uptime Kuma).
* `SUBSCRIPTION_MINI_APP_URL`: (Optional) URL of the Telegram mini app for viewing subscription details. If set, the "My Subscription" button will open this mini app and the bot will register it automatically via API. * `SUBSCRIPTION_MINI_APP_URL`: (Optional) URL of the Telegram mini app for viewing subscription details. If set, the "My Subscription" button will open this mini app and the bot will register it automatically via API.
* `START_COMMAND_DESCRIPTION`: (Optional) Description for the `/start` command shown in the bot's menu.
* **YooKassa Settings:** * **YooKassa Settings:**
* `YOOKASSA_SHOP_ID`: Your shop ID from YooKassa. * `YOOKASSA_SHOP_ID`: Your shop ID from YooKassa.
* `YOOKASSA_SECRET_KEY`: Your secret key from YooKassa. * `YOOKASSA_SECRET_KEY`: Your secret key from YooKassa.
+13 -5
View File
@@ -3,7 +3,7 @@ import asyncio
from typing import Callable, Dict, Any, Awaitable, Optional from typing import Callable, Dict, Any, Awaitable, Optional
from aiogram import Bot, Dispatcher, BaseMiddleware, Router, F from aiogram import Bot, Dispatcher, BaseMiddleware, Router, F
from aiogram.types import Update, MenuButtonWebApp, WebAppInfo from aiogram.types import Update, MenuButtonDefault, BotCommand
from aiogram.enums import ParseMode from aiogram.enums import ParseMode
from aiogram.filters import CommandStart, Command from aiogram.filters import CommandStart, Command
from aiogram.client.default import DefaultBotProperties from aiogram.client.default import DefaultBotProperties
@@ -172,12 +172,20 @@ async def on_startup_configured(dispatcher: Dispatcher):
await bot.delete_webhook(drop_pending_updates=True) await bot.delete_webhook(drop_pending_updates=True)
if settings.SUBSCRIPTION_MINI_APP_URL: if settings.SUBSCRIPTION_MINI_APP_URL:
menu_text = i18n_instance.gettext(settings.DEFAULT_LANGUAGE, "menu_my_subscription_inline")
try: try:
await bot.set_chat_menu_button(menu_button=MenuButtonWebApp(text=menu_text, web_app=WebAppInfo(url=settings.SUBSCRIPTION_MINI_APP_URL))) await bot.set_chat_menu_button(MenuButtonDefault())
logging.info("STARTUP: Menu button for subscription mini app set via API.") logging.info("STARTUP: Mini app support enabled with default menu button.")
except Exception as e: except Exception as e:
logging.error(f"STARTUP: Failed to set menu button web app: {e}", exc_info=True) logging.error(f"STARTUP: Failed to set default menu button: {e}", exc_info=True)
if settings.START_COMMAND_DESCRIPTION:
try:
await bot.set_my_commands([
BotCommand(command="start", description=settings.START_COMMAND_DESCRIPTION)
])
logging.info("STARTUP: /start command description set.")
except Exception as e:
logging.error(f"STARTUP: Failed to set bot commands: {e}", exc_info=True)
logging.info("STARTUP: Bot on_startup_configured completed.") logging.info("STARTUP: Bot on_startup_configured completed.")
+2
View File
@@ -103,6 +103,8 @@ class Settings(BaseSettings):
SUBSCRIPTION_MINI_APP_URL: Optional[str] = Field(default=None) SUBSCRIPTION_MINI_APP_URL: Optional[str] = Field(default=None)
START_COMMAND_DESCRIPTION: Optional[str] = Field(default=None)
@computed_field @computed_field
@property @property
def DATABASE_URL(self) -> str: def DATABASE_URL(self) -> str: