Merge pull request #26 from machka-pasla/codex/добавить-поддержку-mini-app-для-подписки
Support subscription mini app
This commit is contained in:
@@ -16,6 +16,7 @@ DEFAULT_CURRENCY_SYMBOL="RUB" # e.g., RUB, USD, EUR
|
|||||||
SUPPORT_LINK=https://t.me/your_support_link
|
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=
|
||||||
|
|
||||||
# YooKassa Payment Gateway Configuration
|
# YooKassa Payment Gateway Configuration
|
||||||
YOOKASSA_SHOP_ID=your_shop_id
|
YOOKASSA_SHOP_ID=your_shop_id
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ This Telegram bot is designed to automate the sale and management of subscriptio
|
|||||||
* `DEFAULT_CURRENCY_SYMBOL`: e.g., `RUB`, `USD`.
|
* `DEFAULT_CURRENCY_SYMBOL`: e.g., `RUB`, `USD`.
|
||||||
* `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.
|
||||||
* **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.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from aiogram.utils.keyboard import InlineKeyboardBuilder, InlineKeyboardButton
|
from aiogram.utils.keyboard import InlineKeyboardBuilder, InlineKeyboardButton
|
||||||
from aiogram.types import InlineKeyboardMarkup
|
from aiogram.types import InlineKeyboardMarkup, WebAppInfo
|
||||||
from typing import Dict, Optional, List
|
from typing import Dict, Optional, List
|
||||||
|
|
||||||
from config.settings import Settings
|
from config.settings import Settings
|
||||||
@@ -21,9 +21,20 @@ def get_main_menu_inline_keyboard(
|
|||||||
builder.row(
|
builder.row(
|
||||||
InlineKeyboardButton(text=_(key="menu_subscribe_inline"),
|
InlineKeyboardButton(text=_(key="menu_subscribe_inline"),
|
||||||
callback_data="main_action:subscribe"))
|
callback_data="main_action:subscribe"))
|
||||||
builder.row(
|
if settings.SUBSCRIPTION_MINI_APP_URL:
|
||||||
InlineKeyboardButton(text=_(key="menu_my_subscription_inline"),
|
builder.row(
|
||||||
callback_data="main_action:my_subscription"))
|
InlineKeyboardButton(
|
||||||
|
text=_(key="menu_my_subscription_inline"),
|
||||||
|
web_app=WebAppInfo(url=settings.SUBSCRIPTION_MINI_APP_URL),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
builder.row(
|
||||||
|
InlineKeyboardButton(
|
||||||
|
text=_(key="menu_my_subscription_inline"),
|
||||||
|
callback_data="main_action:my_subscription",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
referral_button = InlineKeyboardButton(
|
referral_button = InlineKeyboardButton(
|
||||||
text=_(key="menu_referral_inline"),
|
text=_(key="menu_referral_inline"),
|
||||||
|
|||||||
+9
-1
@@ -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
|
from aiogram.types import Update, MenuButtonWebApp, WebAppInfo
|
||||||
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
|
||||||
@@ -171,6 +171,14 @@ 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:
|
||||||
|
menu_text = i18n_instance.gettext(settings.DEFAULT_LANGUAGE, "menu_my_subscription_inline")
|
||||||
|
try:
|
||||||
|
await bot.set_chat_menu_button(menu_button=MenuButtonWebApp(text=menu_text, web_app=WebAppInfo(url=settings.SUBSCRIPTION_MINI_APP_URL)))
|
||||||
|
logging.info("STARTUP: Menu button for subscription mini app set via API.")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"STARTUP: Failed to set menu button web app: {e}", exc_info=True)
|
||||||
|
|
||||||
logging.info("STARTUP: Bot on_startup_configured completed.")
|
logging.info("STARTUP: Bot on_startup_configured completed.")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ class Settings(BaseSettings):
|
|||||||
WEB_SERVER_PORT: int = Field(default=8080)
|
WEB_SERVER_PORT: int = Field(default=8080)
|
||||||
LOGS_PAGE_SIZE: int = Field(default=10)
|
LOGS_PAGE_SIZE: int = Field(default=10)
|
||||||
|
|
||||||
|
SUBSCRIPTION_MINI_APP_URL: Optional[str] = Field(default=None)
|
||||||
|
|
||||||
@computed_field
|
@computed_field
|
||||||
@property
|
@property
|
||||||
def DATABASE_URL(self) -> str:
|
def DATABASE_URL(self) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user