zov-tech/bot/handlers/start.py
wasrusgen 1ca8b3a5a1 bot: role buttons → MiniApp directly + branded splash loader
Bot: упрощён до одного шага — /start показывает 2 reply-кнопки
[👤 Я менеджер] [🏠 Я клиент], обе уже WebApp — открывают кабинет
сразу с нужным role= в query. Никаких промежуточных меню.

MiniApp: новый брендированный загрузочный экран с логотипом ZOV
(inline SVG, fill = walnut #6B4A2B), дыхательной анимацией 2.2s,
тонкой полоской прогресса и подписью «Открываем кабинет · ZOV».
Splash прячется (350мс минимум + fade-out) после рендера главного
экрана или маунта подэкрана (Podbor/Clients/Measurements).

Cache bust v=20260513c.
2026-05-12 18:54:09 +03:00

77 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import time
from aiogram import F, Router
from aiogram.filters import Command, CommandStart
from aiogram.types import (
KeyboardButton,
Message,
ReplyKeyboardMarkup,
ReplyKeyboardRemove,
WebAppInfo,
)
from config import Config
router = Router(name="start")
# ============================================================
# URL helpers
# ============================================================
def _bust_cache(url: str) -> str:
"""Append unique timestamp so Telegram WebView не кеширует между сессиями."""
sep = "&" if "?" in url else "?"
return f"{url}{sep}t={int(time.time())}"
def _with_query(url: str, **params: str) -> str:
sep = "&" if "?" in url else "?"
pairs = "&".join(f"{k}={v}" for k, v in params.items() if v)
return f"{url}{sep}{pairs}" if pairs else url
def _wapp(miniapp_url: str, role: str) -> WebAppInfo:
return WebAppInfo(url=_bust_cache(_with_query(miniapp_url, role=role)))
# ============================================================
# Reply keyboard — выбор роли. Оба кнопки сразу открывают MiniApp.
# ============================================================
def role_choice_kb(miniapp_url: str) -> ReplyKeyboardMarkup:
return ReplyKeyboardMarkup(
keyboard=[
[
KeyboardButton(text="👤 Я менеджер", web_app=_wapp(miniapp_url, "manager")),
KeyboardButton(text="🏠 Я клиент", web_app=_wapp(miniapp_url, "client")),
],
],
resize_keyboard=True,
is_persistent=True,
input_field_placeholder="Выберите кто вы…",
)
# ============================================================
# Commands
# ============================================================
@router.message(CommandStart())
async def cmd_start(message: Message, config: Config) -> None:
await message.answer(
"👋 Здравствуйте, я бот-помощник от Руслана ВАСИЛЬЕВА.\n\n"
"Выберите, кто вы — кабинет откроется одним тапом.",
reply_markup=role_choice_kb(config.miniapp_url),
)
@router.message(Command("menu"))
async def cmd_menu(message: Message, config: Config) -> None:
await message.answer("Выберите роль:", reply_markup=role_choice_kb(config.miniapp_url))
@router.message(Command("hide"))
async def cmd_hide(message: Message) -> None:
await message.answer("Клавиатура скрыта. Вернуть — /menu", reply_markup=ReplyKeyboardRemove())