From 729ee8646e1cadcdb4878dd140cd6150883f5cdd Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:29:15 +0200 Subject: [PATCH] Mini App: Verify age check bot (#6893) --- .../modals/webApp/WebAppModalTabContent.tsx | 39 +++++++++++++++++-- .../modals/webApp/hooks/useWebAppFrame.ts | 23 ----------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/components/modals/webApp/WebAppModalTabContent.tsx b/src/components/modals/webApp/WebAppModalTabContent.tsx index 27f6c772e..62c03770b 100644 --- a/src/components/modals/webApp/WebAppModalTabContent.tsx +++ b/src/components/modals/webApp/WebAppModalTabContent.tsx @@ -13,7 +13,7 @@ import type { WebAppOutboundEvent, } from '../../../types/webapp'; -import { TME_LINK_PREFIX } from '../../../config'; +import { TME_LINK_PREFIX, VERIFY_AGE_MIN_DEFAULT } from '../../../config'; import { convertToApiChatType, getUserFullName } from '../../../global/helpers'; import { getWebAppKey } from '../../../global/helpers/bots'; import { @@ -88,6 +88,8 @@ type StateProps = { paymentStatus?: TabState['payment']['status']; modalState?: WebAppModalStateType; botAppPermissions?: BotAppPermissions; + verifyAgeMin?: number; + verifyAgeBotUsername?: string; }; const MAIN_BUTTON_ANIMATION_TIME = 250; @@ -120,15 +122,17 @@ const WebAppModalTabContent: FC = ({ theme, isPaymentModalOpen, paymentStatus, - registerSendEventCallback, - registerReloadFrameCallback, isTransforming, modalState, isMultiTabSupported, - onContextMenuButtonClick, botAppPermissions, botAppSettings, modalHeight, + verifyAgeMin = VERIFY_AGE_MIN_DEFAULT, + verifyAgeBotUsername, + registerSendEventCallback, + registerReloadFrameCallback, + onContextMenuButtonClick, }) => { const { closeActiveWebApp, @@ -147,6 +151,7 @@ const WebAppModalTabContent: FC = ({ changeWebAppModalState, closeWebAppModal, openPreparedInlineMessageModal, + updateContentSettings, } = getActions(); const [mainButton, setMainButton] = useState(); const [secondaryButton, setSecondaryButton] = useState(); @@ -832,6 +837,29 @@ const WebAppModalTabContent: FC = ({ if (eventType === 'web_app_read_text_from_clipboard') { setClipboardRequestId(eventData.req_id); } + + if (eventType === 'web_app_verify_age') { + if (!bot?.usernames?.some((username) => username.username === verifyAgeBotUsername)) return; + + const { passed } = eventData; + const minAge = verifyAgeMin; + const ageFromParam = eventData.age || 0; + + if (passed && ageFromParam >= minAge) { + showNotification({ + message: { + key: 'TitleAgeCheckSuccess', + }, + }); + updateContentSettings({ isSensitiveEnabled: true }); + } else { + showNotification({ + message: { + key: 'TitleAgeCheckFailed', + }, + }); + } + } } const mainButtonCurrentColor = useCurrentOrPrev(mainButton?.color, true); @@ -1302,6 +1330,7 @@ export default memo(withGlobal( const activeWebApp = modal?.activeWebAppKey ? selectWebApp(global, modal.activeWebAppKey) : undefined; const { botId: activeBotId } = activeWebApp || {}; const modalState = modal?.modalState; + const { verifyAgeMin, verifyAgeBotUsername } = global.appConfig; const attachBot = activeBotId ? global.attachMenu.bots[activeBotId] : undefined; const bot = activeBotId ? selectUser(global, activeBotId) : undefined; @@ -1325,6 +1354,8 @@ export default memo(withGlobal( modalState, botAppPermissions, botAppSettings, + verifyAgeMin, + verifyAgeBotUsername, }; }, )(WebAppModalTabContent)); diff --git a/src/components/modals/webApp/hooks/useWebAppFrame.ts b/src/components/modals/webApp/hooks/useWebAppFrame.ts index 026c5c4b0..749a97aa4 100644 --- a/src/components/modals/webApp/hooks/useWebAppFrame.ts +++ b/src/components/modals/webApp/hooks/useWebAppFrame.ts @@ -4,7 +4,6 @@ import { getActions, getGlobal } from '../../../../global'; import type { WebApp, WebAppInboundEvent, WebAppOutboundEvent } from '../../../../types/webapp'; -import { VERIFY_AGE_MIN_DEFAULT } from '../../../../config'; import { getWebAppKey } from '../../../../global/helpers'; import { isMessageFromIframe } from '../../../../util/browser/iframe'; import { isValidProtocol } from '../../../../util/browser/url'; @@ -53,7 +52,6 @@ const useWebAppFrame = ( closeWebApp, openSuggestedStatusModal, updateWebApp, - updateContentSettings, } = getActions(); const isReloadSupportedRef = useRef(false); @@ -375,27 +373,6 @@ const useWebAppFrame = ( }); } - if (eventType === 'web_app_verify_age') { - const { passed } = eventData; - const minAge = getGlobal().appConfig.verifyAgeMin || VERIFY_AGE_MIN_DEFAULT; - const ageFromParam = eventData.age || 0; - - if (passed && ageFromParam >= minAge) { - showNotification({ - message: { - key: 'TitleAgeCheckSuccess', - }, - }); - updateContentSettings({ isSensitiveEnabled: true }); - } else { - showNotification({ - message: { - key: 'TitleAgeCheckFailed', - }, - }); - } - } - onEvent(data); } catch (err) { // Ignore other messages