Mini App: Verify age check bot (#6893)

This commit is contained in:
zubiden 2026-04-27 14:29:15 +02:00 committed by Alexander Zinchuk
parent 04d45b2275
commit 729ee8646e
2 changed files with 35 additions and 27 deletions

View File

@ -13,7 +13,7 @@ import type {
WebAppOutboundEvent, WebAppOutboundEvent,
} from '../../../types/webapp'; } 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 { convertToApiChatType, getUserFullName } from '../../../global/helpers';
import { getWebAppKey } from '../../../global/helpers/bots'; import { getWebAppKey } from '../../../global/helpers/bots';
import { import {
@ -88,6 +88,8 @@ type StateProps = {
paymentStatus?: TabState['payment']['status']; paymentStatus?: TabState['payment']['status'];
modalState?: WebAppModalStateType; modalState?: WebAppModalStateType;
botAppPermissions?: BotAppPermissions; botAppPermissions?: BotAppPermissions;
verifyAgeMin?: number;
verifyAgeBotUsername?: string;
}; };
const MAIN_BUTTON_ANIMATION_TIME = 250; const MAIN_BUTTON_ANIMATION_TIME = 250;
@ -120,15 +122,17 @@ const WebAppModalTabContent: FC<OwnProps & StateProps> = ({
theme, theme,
isPaymentModalOpen, isPaymentModalOpen,
paymentStatus, paymentStatus,
registerSendEventCallback,
registerReloadFrameCallback,
isTransforming, isTransforming,
modalState, modalState,
isMultiTabSupported, isMultiTabSupported,
onContextMenuButtonClick,
botAppPermissions, botAppPermissions,
botAppSettings, botAppSettings,
modalHeight, modalHeight,
verifyAgeMin = VERIFY_AGE_MIN_DEFAULT,
verifyAgeBotUsername,
registerSendEventCallback,
registerReloadFrameCallback,
onContextMenuButtonClick,
}) => { }) => {
const { const {
closeActiveWebApp, closeActiveWebApp,
@ -147,6 +151,7 @@ const WebAppModalTabContent: FC<OwnProps & StateProps> = ({
changeWebAppModalState, changeWebAppModalState,
closeWebAppModal, closeWebAppModal,
openPreparedInlineMessageModal, openPreparedInlineMessageModal,
updateContentSettings,
} = getActions(); } = getActions();
const [mainButton, setMainButton] = useState<WebAppButton>(); const [mainButton, setMainButton] = useState<WebAppButton>();
const [secondaryButton, setSecondaryButton] = useState<WebAppButton>(); const [secondaryButton, setSecondaryButton] = useState<WebAppButton>();
@ -832,6 +837,29 @@ const WebAppModalTabContent: FC<OwnProps & StateProps> = ({
if (eventType === 'web_app_read_text_from_clipboard') { if (eventType === 'web_app_read_text_from_clipboard') {
setClipboardRequestId(eventData.req_id); 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); const mainButtonCurrentColor = useCurrentOrPrev(mainButton?.color, true);
@ -1302,6 +1330,7 @@ export default memo(withGlobal<OwnProps>(
const activeWebApp = modal?.activeWebAppKey ? selectWebApp(global, modal.activeWebAppKey) : undefined; const activeWebApp = modal?.activeWebAppKey ? selectWebApp(global, modal.activeWebAppKey) : undefined;
const { botId: activeBotId } = activeWebApp || {}; const { botId: activeBotId } = activeWebApp || {};
const modalState = modal?.modalState; const modalState = modal?.modalState;
const { verifyAgeMin, verifyAgeBotUsername } = global.appConfig;
const attachBot = activeBotId ? global.attachMenu.bots[activeBotId] : undefined; const attachBot = activeBotId ? global.attachMenu.bots[activeBotId] : undefined;
const bot = activeBotId ? selectUser(global, activeBotId) : undefined; const bot = activeBotId ? selectUser(global, activeBotId) : undefined;
@ -1325,6 +1354,8 @@ export default memo(withGlobal<OwnProps>(
modalState, modalState,
botAppPermissions, botAppPermissions,
botAppSettings, botAppSettings,
verifyAgeMin,
verifyAgeBotUsername,
}; };
}, },
)(WebAppModalTabContent)); )(WebAppModalTabContent));

View File

@ -4,7 +4,6 @@ import { getActions, getGlobal } from '../../../../global';
import type { WebApp, WebAppInboundEvent, WebAppOutboundEvent } from '../../../../types/webapp'; import type { WebApp, WebAppInboundEvent, WebAppOutboundEvent } from '../../../../types/webapp';
import { VERIFY_AGE_MIN_DEFAULT } from '../../../../config';
import { getWebAppKey } from '../../../../global/helpers'; import { getWebAppKey } from '../../../../global/helpers';
import { isMessageFromIframe } from '../../../../util/browser/iframe'; import { isMessageFromIframe } from '../../../../util/browser/iframe';
import { isValidProtocol } from '../../../../util/browser/url'; import { isValidProtocol } from '../../../../util/browser/url';
@ -53,7 +52,6 @@ const useWebAppFrame = (
closeWebApp, closeWebApp,
openSuggestedStatusModal, openSuggestedStatusModal,
updateWebApp, updateWebApp,
updateContentSettings,
} = getActions(); } = getActions();
const isReloadSupportedRef = useRef<boolean>(false); const isReloadSupportedRef = useRef<boolean>(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); onEvent(data);
} catch (err) { } catch (err) {
// Ignore other messages // Ignore other messages