This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, WebAppInfo
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
def _mini_app_url(path: str = "") -> str:
|
||||
base = settings.mini_app_url.rstrip("/") + "/"
|
||||
return urljoin(base, path.lstrip("/"))
|
||||
|
||||
|
||||
def main_menu_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(inline_keyboard=[[
|
||||
InlineKeyboardButton(
|
||||
text="Open lottery app",
|
||||
web_app=WebAppInfo(url=_mini_app_url()),
|
||||
)
|
||||
]])
|
||||
|
||||
|
||||
def create_lottery_keyboard() -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardMarkup(inline_keyboard=[[
|
||||
InlineKeyboardButton(
|
||||
text="Create lottery",
|
||||
web_app=WebAppInfo(url=_mini_app_url("/create")),
|
||||
)
|
||||
]])
|
||||
|
||||
|
||||
def lottery_detail_keyboard(lottery_id: str, text: str = "🎰 Join lottery") -> InlineKeyboardMarkup:
|
||||
"""For private chat messages - web_app is allowed here."""
|
||||
return InlineKeyboardMarkup(inline_keyboard=[[
|
||||
InlineKeyboardButton(
|
||||
text=text,
|
||||
web_app=WebAppInfo(url=_mini_app_url(f"/lottery/{lottery_id}")),
|
||||
)
|
||||
]])
|
||||
|
||||
|
||||
def lottery_announce_keyboard(lottery_id: str) -> InlineKeyboardMarkup:
|
||||
"""For group/channel announcements - web_app is not allowed; use t.me deep link."""
|
||||
from app.bot.router import bot_username
|
||||
if bot_username:
|
||||
url = f"https://t.me/{bot_username}?start=lottery_{lottery_id}"
|
||||
else:
|
||||
url = _mini_app_url(f"/lottery/{lottery_id}")
|
||||
return InlineKeyboardMarkup(inline_keyboard=[[
|
||||
InlineKeyboardButton(text="🎰 Join lottery", url=url)
|
||||
]])
|
||||
Reference in New Issue
Block a user