Files
remnawave-bedolaga-telegram…/app/utils/miniapp_buttons.py
T
Fringg eaf3a07579 fix: use callback fallback when MINIAPP_CUSTOM_URL is not set
Only consider MINIAPP_CUSTOM_URL for miniapp buttons, not the
purchase-only MINIAPP_PURCHASE_URL which cannot display subscription
info and loads indefinitely. When no custom URL is configured, fall
back to regular callback_data so the bot shows subscription natively.
2026-02-11 01:58:40 +03:00

32 lines
1.1 KiB
Python

from aiogram import types
from aiogram.types import InlineKeyboardButton
from app.config import settings
def build_miniapp_or_callback_button(
text: str,
*,
callback_data: str,
) -> InlineKeyboardButton:
"""Create a button that opens the miniapp or falls back to a callback.
In text menu mode, if ``MINIAPP_CUSTOM_URL`` is configured the button
opens the full cabinet miniapp. Otherwise (or outside text menu mode)
the regular ``callback_data`` is used so the user stays in the bot.
Only ``MINIAPP_CUSTOM_URL`` is considered here — the purchase-only URL
(``MINIAPP_PURCHASE_URL``) is intentionally excluded because it cannot
display subscription details and would load indefinitely.
"""
if settings.is_text_main_menu_mode():
miniapp_url = (settings.MINIAPP_CUSTOM_URL or '').strip()
if miniapp_url:
return InlineKeyboardButton(
text=text,
web_app=types.WebAppInfo(url=miniapp_url),
)
return InlineKeyboardButton(text=text, callback_data=callback_data)