diff --git a/.env.example b/.env.example index 850a61c..ce2e48c 100644 --- a/.env.example +++ b/.env.example @@ -17,6 +17,8 @@ DEFAULT_CURRENCY_SYMBOL="RUB" # SUPPORT_LINK=https://t.me/your_support_link # Link to the support chat SERVER_STATUS_URL=https://status.yourdomain.tld/status/your_service # Link to the server status page TERMS_OF_SERVICE_URL=https://example.com/tos # Link to the terms of service +PRIVACY_POLICY_URL=https://example.com/privacy # Link to the privacy policy +USER_AGREEMENT_URL=https://example.com/user-agreement # Link to the user agreement SUBSCRIPTION_MINI_APP_URL= # URL of the subscription mini-app START_COMMAND_DESCRIPTION= # Description of the /start command DISABLE_WELCOME_MESSAGE= # Disable the welcome message diff --git a/bot/handlers/user/start.py b/bot/handlers/user/start.py index cd2d980..54ec2a8 100644 --- a/bot/handlers/user/start.py +++ b/bot/handlers/user/start.py @@ -16,6 +16,7 @@ from bot.keyboards.inline.user_keyboards import ( get_main_menu_inline_keyboard, get_language_selection_keyboard, get_channel_subscription_keyboard, + get_information_links_keyboard, ) from bot.services.subscription_service import SubscriptionService from bot.services.panel_api_service import PanelApiService @@ -696,6 +697,38 @@ async def main_action_callback_handler( elif action == "language": await language_command_handler(callback, i18n_data, settings) + elif action == "info": + i18n: Optional[JsonI18n] = i18n_data.get("i18n_instance") + current_lang = i18n_data.get("current_language", + settings.DEFAULT_LANGUAGE) + if not i18n: + await callback.answer("Language service error.", + show_alert=True) + return + _ = lambda key, **kwargs: i18n.gettext( + current_lang, key, **kwargs) if i18n else key + + privacy_url = settings.PRIVACY_POLICY_URL + user_agreement_url = settings.USER_AGREEMENT_URL or settings.TERMS_OF_SERVICE_URL + + if not privacy_url and not user_agreement_url: + await callback.answer(_("error_occurred_try_again"), + show_alert=True) + return + + reply_markup = get_information_links_keyboard( + current_lang, + i18n, + privacy_url, + user_agreement_url, + ) + try: + await callback.message.edit_text(_(key="info_links_message"), + reply_markup=reply_markup) + except Exception: + await callback.message.answer(_(key="info_links_message"), + reply_markup=reply_markup) + await callback.answer() elif action == "back_to_main": await send_main_menu(callback, settings, diff --git a/bot/keyboards/inline/user_keyboards.py b/bot/keyboards/inline/user_keyboards.py index 5f9020e..02bcca0 100644 --- a/bot/keyboards/inline/user_keyboards.py +++ b/bot/keyboards/inline/user_keyboards.py @@ -55,14 +55,36 @@ def get_main_menu_inline_keyboard( InlineKeyboardButton(text=_(key="menu_support_button"), url=settings.SUPPORT_LINK)) - if settings.TERMS_OF_SERVICE_URL: + user_agreement_url = settings.USER_AGREEMENT_URL or settings.TERMS_OF_SERVICE_URL + if settings.PRIVACY_POLICY_URL or user_agreement_url: builder.row( - InlineKeyboardButton(text=_(key="menu_terms_button"), - url=settings.TERMS_OF_SERVICE_URL)) + InlineKeyboardButton(text=_(key="menu_info_button"), + callback_data="main_action:info")) return builder.as_markup() +def get_information_links_keyboard( + lang: str, + i18n_instance, + privacy_policy_url: Optional[str], + user_agreement_url: Optional[str]) -> InlineKeyboardMarkup: + _ = lambda key, **kwargs: i18n_instance.gettext(lang, key, **kwargs) + builder = InlineKeyboardBuilder() + if privacy_policy_url: + builder.row( + InlineKeyboardButton(text=_(key="privacy_policy_button"), + url=privacy_policy_url)) + if user_agreement_url: + builder.row( + InlineKeyboardButton(text=_(key="user_agreement_button"), + url=user_agreement_url)) + builder.row( + InlineKeyboardButton(text=_(key="back_to_main_menu_button"), + callback_data="main_action:back_to_main")) + return builder.as_markup() + + def get_language_selection_keyboard(i18n_instance, current_lang: str) -> InlineKeyboardMarkup: _ = lambda key, **kwargs: i18n_instance.gettext(current_lang, key, **kwargs diff --git a/config/settings.py b/config/settings.py index 4e029ea..4638973 100644 --- a/config/settings.py +++ b/config/settings.py @@ -23,6 +23,8 @@ class Settings(BaseSettings): SUPPORT_LINK: Optional[str] = Field(default=None) SERVER_STATUS_URL: Optional[str] = Field(default=None) TERMS_OF_SERVICE_URL: Optional[str] = Field(default=None) + PRIVACY_POLICY_URL: Optional[str] = Field(default=None) + USER_AGREEMENT_URL: Optional[str] = Field(default=None) REQUIRED_CHANNEL_ID: Optional[int] = Field( default=None, description="Telegram channel ID the user must join to access the bot") @@ -505,6 +507,8 @@ class Settings(BaseSettings): 'PLATEGA_FAILED_URL', 'SEVERPAY_RETURN_URL', 'CRYPT4_REDIRECT_URL', + 'PRIVACY_POLICY_URL', + 'USER_AGREEMENT_URL', mode='before', ) @classmethod diff --git a/locales/en.json b/locales/en.json index 7732f34..7db20a9 100644 --- a/locales/en.json +++ b/locales/en.json @@ -17,6 +17,10 @@ "menu_server_status_button": "📊 Status", "menu_support_button": "💬 Support", "menu_terms_button": "📄 Terms of Service", + "menu_info_button": "ℹ️ Information", + "info_links_message": "Choose a document:", + "privacy_policy_button": "🔒 Privacy Policy", + "user_agreement_button": "📄 User Agreement", "back_to_main_menu_button": "⬅️ Back", "choose_language": "Choose language:", "language_set_alert": "Language changed!", diff --git a/locales/ru.json b/locales/ru.json index de5f44d..28e9bd6 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -17,6 +17,10 @@ "menu_server_status_button": "📊 Статус", "menu_support_button": "💬 Поддержка", "menu_terms_button": "📄 Условия сервиса", + "menu_info_button": "ℹ️ Информация", + "info_links_message": "Выберите документ:", + "privacy_policy_button": "🔒 Политика конфиденциальности", + "user_agreement_button": "📄 Пользовательское соглашение", "back_to_main_menu_button": "⬅️ Назад", "choose_language": "Выберите язык / Select language:", "language_set_alert": "Язык изменен!",