From e94e5f36715a02b8169a4dc2b2f56b9634111fbf Mon Sep 17 00:00:00 2001 From: Vladislav Kibenko Date: Fri, 17 Nov 2023 19:01:59 +0300 Subject: [PATCH 1/3] feat(docs): split docs on "Platform" and "Packages" --- apps/docs/.vitepress/config.mts | 197 +------ apps/docs/.vitepress/packages.ts | 103 ++++ apps/docs/.vitepress/platform.ts | 64 +++ apps/docs/{ => docs}/about-platform.md | 0 .../{ => docs}/apps-communication/events.md | 0 .../apps-communication/flow-definition.md | 0 .../{ => docs}/apps-communication/methods.md | 0 .../functionality/closing-behavior.md | 0 .../functionality/haptic-feedback.md | 0 apps/docs/{ => docs}/functionality/theming.md | 0 .../docs/{ => docs}/functionality/viewport.md | 0 .../{ => docs}/guides/creating-new-app.md | 0 .../launch-parameters/common-information.md | 0 .../{ => docs}/launch-parameters/init-data.md | 0 apps/docs/{ => docs}/test-environment.md | 0 apps/docs/{ => docs}/ui/back-button.md | 0 apps/docs/{ => docs}/ui/main-button.md | 0 apps/docs/{ => docs}/ui/popup.md | 0 apps/docs/{ => docs}/ui/settings-button.md | 0 apps/docs/packages/golang/init-data-golang.md | 2 +- .../tma-js-init-data-node.md | 6 +- .../typescript/tma-js-init-data/about.md | 4 +- .../typescript/tma-js-launch-params.md | 2 +- .../packages/typescript/tma-js-sdk/about.md | 4 +- .../tma-js-sdk/components/back-button.md | 2 +- .../components/closing-behaviour.md | 2 +- .../tma-js-sdk/components/haptic-feedback.md | 2 +- .../tma-js-sdk/components/init-data.md | 2 +- .../tma-js-sdk/components/main-button.md | 2 +- .../typescript/tma-js-sdk/components/popup.md | 2 +- .../tma-js-sdk/components/theme-params.md | 2 +- .../tma-js-sdk/components/viewport.md | 2 +- .../tma-js-sdk/components/web-app.md | 2 +- .../typescript/tma-js-theme-params.md | 2 +- apps/docs/platform/about-platform.md | 75 +++ .../platform/apps-communication/events.md | 254 ++++++++ .../apps-communication/flow-definition.md | 23 + .../platform/apps-communication/methods.md | 544 ++++++++++++++++++ .../functionality/closing-behavior.md | 14 + .../platform/functionality/haptic-feedback.md | 23 + apps/docs/platform/functionality/theming.md | 62 ++ apps/docs/platform/functionality/viewport.md | 31 + apps/docs/platform/guides/creating-new-app.md | 178 ++++++ .../launch-parameters/common-information.md | 103 ++++ .../platform/launch-parameters/init-data.md | 344 +++++++++++ apps/docs/platform/test-environment.md | 31 + apps/docs/platform/ui/back-button.md | 17 + apps/docs/platform/ui/main-button.md | 26 + apps/docs/platform/ui/popup.md | 13 + apps/docs/platform/ui/settings-button.md | 16 + 50 files changed, 1953 insertions(+), 203 deletions(-) create mode 100644 apps/docs/.vitepress/packages.ts create mode 100644 apps/docs/.vitepress/platform.ts rename apps/docs/{ => docs}/about-platform.md (100%) rename apps/docs/{ => docs}/apps-communication/events.md (100%) rename apps/docs/{ => docs}/apps-communication/flow-definition.md (100%) rename apps/docs/{ => docs}/apps-communication/methods.md (100%) rename apps/docs/{ => docs}/functionality/closing-behavior.md (100%) rename apps/docs/{ => docs}/functionality/haptic-feedback.md (100%) rename apps/docs/{ => docs}/functionality/theming.md (100%) rename apps/docs/{ => docs}/functionality/viewport.md (100%) rename apps/docs/{ => docs}/guides/creating-new-app.md (100%) rename apps/docs/{ => docs}/launch-parameters/common-information.md (100%) rename apps/docs/{ => docs}/launch-parameters/init-data.md (100%) rename apps/docs/{ => docs}/test-environment.md (100%) rename apps/docs/{ => docs}/ui/back-button.md (100%) rename apps/docs/{ => docs}/ui/main-button.md (100%) rename apps/docs/{ => docs}/ui/popup.md (100%) rename apps/docs/{ => docs}/ui/settings-button.md (100%) rename apps/docs/packages/{typescript => node}/tma-js-init-data-node.md (89%) create mode 100644 apps/docs/platform/about-platform.md create mode 100644 apps/docs/platform/apps-communication/events.md create mode 100644 apps/docs/platform/apps-communication/flow-definition.md create mode 100644 apps/docs/platform/apps-communication/methods.md create mode 100644 apps/docs/platform/functionality/closing-behavior.md create mode 100644 apps/docs/platform/functionality/haptic-feedback.md create mode 100644 apps/docs/platform/functionality/theming.md create mode 100644 apps/docs/platform/functionality/viewport.md create mode 100644 apps/docs/platform/guides/creating-new-app.md create mode 100644 apps/docs/platform/launch-parameters/common-information.md create mode 100644 apps/docs/platform/launch-parameters/init-data.md create mode 100644 apps/docs/platform/test-environment.md create mode 100644 apps/docs/platform/ui/back-button.md create mode 100644 apps/docs/platform/ui/main-button.md create mode 100644 apps/docs/platform/ui/popup.md create mode 100644 apps/docs/platform/ui/settings-button.md diff --git a/apps/docs/.vitepress/config.mts b/apps/docs/.vitepress/config.mts index 8e6855f37..487d4ba57 100644 --- a/apps/docs/.vitepress/config.mts +++ b/apps/docs/.vitepress/config.mts @@ -1,5 +1,8 @@ import { defineConfig } from 'vitepress'; +import { packagesNavItem, packagesSidebar } from './packages'; +import { platformNavItem, platformSidebar } from './platform'; + // https://vitepress.dev/reference/site-config export default defineConfig({ title: 'Telegram Mini Apps', @@ -12,17 +15,6 @@ export default defineConfig({ label: 'English', lang: 'en', }, - // ru: { - // label: 'Русский', - // lang: 'ru', - // description: 'Документация, покрывающая все аспекты платформы Telegram - Telegram Mini Apps.', - // themeConfig: { - // editLink: { - // text: 'Редактировать эту страницу на GitHub', - // pattern: 'https://github.com/telegram-mini-apps/tma.js/edit/master/apps/docs/src/:path', - // }, - // }, - // }, }, // Show when each page content was last updated. @@ -64,187 +56,24 @@ export default defineConfig({ // https://vitepress.dev/reference/default-theme-config nav: [ { text: 'Home', link: '/' }, - { text: 'Documentation', link: '/about-platform' }, + platformNavItem, + packagesNavItem, ], // https://vitepress.dev/reference/default-theme-sidebar - sidebar: [ - { - text: 'Common information', - items: [ - { text: 'About platform', link: '/about-platform' }, - { text: 'Test environment', link: '/test-environment' }, - ], - }, - - { - text: 'Apps communication', - items: [ - { text: 'Flow definition', link: '/apps-communication/flow-definition' }, - { text: 'Methods', link: '/apps-communication/methods' }, - { text: 'Events', link: '/apps-communication/events' }, - ], - }, - - { - text: 'Launch parameters', - items: [ - { text: 'Common information', link: '/launch-parameters/common-information' }, - { text: 'Init data', link: '/launch-parameters/init-data' }, - ], - }, - - { - text: 'Functionality', - items: [ - { text: 'Closing behavior', link: '/functionality/closing-behavior' }, - { text: 'Haptic feedback', link: '/functionality/haptic-feedback' }, - { text: 'Theming', link: '/functionality/theming' }, - { text: 'Viewport', link: '/functionality/viewport' }, - ], - }, - - { - text: 'UI', - items: [ - { text: 'Back Button', link: '/ui/back-button' }, - { text: 'Main Button', link: '/ui/main-button' }, - { text: 'Popup', link: '/ui/popup' }, - { text: 'Settings Button', link: '/ui/settings-button' }, - ], - }, - - { - text: 'Packages', - items: [ - { - text: 'TypeScript', - collapsed: true, - items: [ - { text: '@tma.js/bridge', link: '/packages/typescript/tma-js-bridge' }, - { - text: '@tma.js/init-data', - collapsed: true, - items: [ - { text: 'About', link: '/packages/typescript/tma-js-init-data/about' }, - { text: 'InitData', link: '/packages/typescript/tma-js-init-data/init-data' }, - { text: 'Chat', link: '/packages/typescript/tma-js-init-data/chat' }, - { text: 'User', link: '/packages/typescript/tma-js-init-data/user' }, - ], - }, - { - text: '@tma.js/init-data-node', - link: '/packages/typescript/tma-js-init-data-node', - }, - { text: '@tma.js/launch-params', link: '/packages/typescript/tma-js-launch-params' }, - { text: '@tma.js/theme-params', link: '/packages/typescript/tma-js-theme-params' }, - { text: '@tma.js/navigation', link: '/packages/typescript/tma-js-navigation' }, - { - text: '@tma.js/sdk', - collapsed: true, - items: [ - { text: 'About', link: '/packages/typescript/tma-js-sdk/about' }, - { - text: 'Components', - collapsed: true, - items: [ - { - text: 'BackButton', - link: '/packages/typescript/tma-js-sdk/components/back-button', - }, - { - text: 'ClosingBehavior', - link: '/packages/typescript/tma-js-sdk/components/closing-behaviour', - }, - { - text: 'HapticFeedback', - link: '/packages/typescript/tma-js-sdk/components/haptic-feedback', - }, - { - text: 'InitData', - link: '/packages/typescript/tma-js-sdk/components/init-data', - }, - { - text: 'MainButton', - link: '/packages/typescript/tma-js-sdk/components/main-button', - }, - { - text: 'Popup', - link: '/packages/typescript/tma-js-sdk/components/popup', - }, - { - text: 'QRScanner', - link: '/packages/typescript/tma-js-sdk/components/qr-scanner', - }, - { - text: 'ThemeParams', - link: '/packages/typescript/tma-js-sdk/components/theme-params', - }, - { - text: 'Viewport', - link: '/packages/typescript/tma-js-sdk/components/viewport', - }, - // TODO: Rename? - { - text: 'WebApp', - link: '/packages/typescript/tma-js-sdk/components/web-app', - }, - ], - }, - ], - }, - { text: '@tma.js/sdk-react', link: '/packages/typescript/tma-js-sdk-react' }, - { text: '@tma.js/sdk-solid', link: '/packages/typescript/tma-js-sdk-solid' }, - ], - }, - { - text: 'GoLang', - collapsed: true, - items: [ - { text: 'init-data-golang', link: '/packages/golang/init-data-golang' }, - ], - }, - ], - }, - - { - text: 'Guides', - items: [ - { text: 'Creating new app', link: '/guides/creating-new-app' }, - ], - }, - ], + sidebar: { + ...packagesSidebar, + ...platformSidebar, + }, - socialLinks: [ - { icon: 'github', link: 'https://github.com/telegram-mini-apps' }, - ], + socialLinks: [{ + icon: 'github', + link: 'https://github.com/telegram-mini-apps', + }], search: { // TODO: Probably replace with Algolia. provider: 'local', - // options: { - // locales: { - // ru: { - // translations: { - // button: { - // buttonText: 'Поиск', - // buttonAriaLabel: 'Поиск', - // }, - // modal: { - // noResultsText: 'Не удалось ничего найти по запросу', - // backButtonTitle: 'закрыть', - // displayDetails: 'Отобразить подробные данные', - // resetButtonTitle: 'Сбросить', - // footer: { - // selectText: 'выбрать', - // navigateText: 'для навигации', - // closeText: 'закрыть', - // }, - // }, - // }, - // }, - // }, - // }, }, }, }); diff --git a/apps/docs/.vitepress/packages.ts b/apps/docs/.vitepress/packages.ts new file mode 100644 index 000000000..e1f643b5e --- /dev/null +++ b/apps/docs/.vitepress/packages.ts @@ -0,0 +1,103 @@ +function prefixed(value: string): string { + return `/packages${value}`; +} + +export const packagesNavItem = { + text: 'Packages', + link: prefixed('/typescript/tma-js-bridge'), +}; + +export const packagesSidebar = { + [prefixed('/')]: [ + { + text: 'TypeScript', + items: [ + { text: '@tma.js/bridge', link: prefixed('/typescript/tma-js-bridge') }, + { + text: '@tma.js/init-data', + collapsed: true, + items: [ + { text: 'About', link: prefixed('/typescript/tma-js-init-data/about') }, + { text: 'InitData', link: prefixed('/typescript/tma-js-init-data/init-data') }, + { text: 'Chat', link: prefixed('/typescript/tma-js-init-data/chat') }, + { text: 'User', link: prefixed('/typescript/tma-js-init-data/user') }, + ], + }, + { + text: '@tma.js/launch-params', + link: prefixed('/typescript/tma-js-launch-params'), + }, + { text: '@tma.js/theme-params', link: prefixed('/typescript/tma-js-theme-params') }, + { text: '@tma.js/navigation', link: prefixed('/typescript/tma-js-navigation') }, + { + text: '@tma.js/sdk', + collapsed: true, + items: [ + { text: 'About', link: prefixed('/typescript/tma-js-sdk/about') }, + { + text: 'Components', + collapsed: true, + items: [ + { + text: 'BackButton', + link: prefixed('/typescript/tma-js-sdk/components/back-button'), + }, + { + text: 'ClosingBehavior', + link: prefixed('/typescript/tma-js-sdk/components/closing-behaviour'), + }, + { + text: 'HapticFeedback', + link: prefixed('/typescript/tma-js-sdk/components/haptic-feedback'), + }, + { + text: 'InitData', + link: prefixed('/typescript/tma-js-sdk/components/init-data'), + }, + { + text: 'MainButton', + link: prefixed('/typescript/tma-js-sdk/components/main-button'), + }, + { + text: 'Popup', + link: prefixed('/typescript/tma-js-sdk/components/popup'), + }, + { + text: 'QRScanner', + link: prefixed('/typescript/tma-js-sdk/components/qr-scanner'), + }, + { + text: 'ThemeParams', + link: prefixed('/typescript/tma-js-sdk/components/theme-params'), + }, + { + text: 'Viewport', + link: prefixed('/typescript/tma-js-sdk/components/viewport'), + }, + // TODO: Rename? + { + text: 'WebApp', + link: prefixed('/typescript/tma-js-sdk/components/web-app'), + }, + ], + }, + ], + }, + { text: '@tma.js/sdk-react', link: prefixed('/typescript/tma-js-sdk-react') }, + { text: '@tma.js/sdk-solid', link: prefixed('/typescript/tma-js-sdk-solid') }, + ], + }, + { + text: 'Node', + items: [ + { text: '@tma.js/init-data-node', link: prefixed('/node/tma-js-init-data-node') }, + ], + }, + { + text: 'GoLang', + items: [ + { text: 'init-data-golang', link: prefixed('/golang/init-data-golang') }, + ], + }, + ], +}; \ No newline at end of file diff --git a/apps/docs/.vitepress/platform.ts b/apps/docs/.vitepress/platform.ts new file mode 100644 index 000000000..002d5ac3a --- /dev/null +++ b/apps/docs/.vitepress/platform.ts @@ -0,0 +1,64 @@ +function prefixed(value: string): string { + return `/platform${value}`; +} + +export const platformNavItem = { + text: 'Platform', + link: prefixed('/about-platform'), +}; + +export const platformSidebar = { + [prefixed('/')]: [ + { + text: 'Common information', + items: [ + { text: 'About platform', link: prefixed('/about-platform') }, + { text: 'Test environment', link: prefixed('/test-environment') }, + ], + }, + + { + text: 'Apps communication', + items: [ + { text: 'Flow definition', link: prefixed('/apps-communication/flow-definition') }, + { text: 'Methods', link: prefixed('/apps-communication/methods') }, + { text: 'Events', link: prefixed('/apps-communication/events') }, + ], + }, + + { + text: 'Launch parameters', + items: [ + { text: 'Common information', link: prefixed('/launch-parameters/common-information') }, + { text: 'Init data', link: prefixed('/launch-parameters/init-data') }, + ], + }, + + { + text: 'Functionality', + items: [ + { text: 'Closing behavior', link: prefixed('/functionality/closing-behavior') }, + { text: 'Haptic feedback', link: prefixed('/functionality/haptic-feedback') }, + { text: 'Theming', link: prefixed('/functionality/theming') }, + { text: 'Viewport', link: prefixed('/functionality/viewport') }, + ], + }, + + { + text: 'UI', + items: [ + { text: 'Back Button', link: prefixed('/ui/back-button') }, + { text: 'Main Button', link: prefixed('/ui/main-button') }, + { text: 'Popup', link: prefixed('/ui/popup') }, + { text: 'Settings Button', link: prefixed('/ui/settings-button') }, + ], + }, + + { + text: 'Guides', + items: [ + { text: 'Creating new app', link: prefixed('/guides/creating-new-app') }, + ], + }, + ], +}; \ No newline at end of file diff --git a/apps/docs/about-platform.md b/apps/docs/docs/about-platform.md similarity index 100% rename from apps/docs/about-platform.md rename to apps/docs/docs/about-platform.md diff --git a/apps/docs/apps-communication/events.md b/apps/docs/docs/apps-communication/events.md similarity index 100% rename from apps/docs/apps-communication/events.md rename to apps/docs/docs/apps-communication/events.md diff --git a/apps/docs/apps-communication/flow-definition.md b/apps/docs/docs/apps-communication/flow-definition.md similarity index 100% rename from apps/docs/apps-communication/flow-definition.md rename to apps/docs/docs/apps-communication/flow-definition.md diff --git a/apps/docs/apps-communication/methods.md b/apps/docs/docs/apps-communication/methods.md similarity index 100% rename from apps/docs/apps-communication/methods.md rename to apps/docs/docs/apps-communication/methods.md diff --git a/apps/docs/functionality/closing-behavior.md b/apps/docs/docs/functionality/closing-behavior.md similarity index 100% rename from apps/docs/functionality/closing-behavior.md rename to apps/docs/docs/functionality/closing-behavior.md diff --git a/apps/docs/functionality/haptic-feedback.md b/apps/docs/docs/functionality/haptic-feedback.md similarity index 100% rename from apps/docs/functionality/haptic-feedback.md rename to apps/docs/docs/functionality/haptic-feedback.md diff --git a/apps/docs/functionality/theming.md b/apps/docs/docs/functionality/theming.md similarity index 100% rename from apps/docs/functionality/theming.md rename to apps/docs/docs/functionality/theming.md diff --git a/apps/docs/functionality/viewport.md b/apps/docs/docs/functionality/viewport.md similarity index 100% rename from apps/docs/functionality/viewport.md rename to apps/docs/docs/functionality/viewport.md diff --git a/apps/docs/guides/creating-new-app.md b/apps/docs/docs/guides/creating-new-app.md similarity index 100% rename from apps/docs/guides/creating-new-app.md rename to apps/docs/docs/guides/creating-new-app.md diff --git a/apps/docs/launch-parameters/common-information.md b/apps/docs/docs/launch-parameters/common-information.md similarity index 100% rename from apps/docs/launch-parameters/common-information.md rename to apps/docs/docs/launch-parameters/common-information.md diff --git a/apps/docs/launch-parameters/init-data.md b/apps/docs/docs/launch-parameters/init-data.md similarity index 100% rename from apps/docs/launch-parameters/init-data.md rename to apps/docs/docs/launch-parameters/init-data.md diff --git a/apps/docs/test-environment.md b/apps/docs/docs/test-environment.md similarity index 100% rename from apps/docs/test-environment.md rename to apps/docs/docs/test-environment.md diff --git a/apps/docs/ui/back-button.md b/apps/docs/docs/ui/back-button.md similarity index 100% rename from apps/docs/ui/back-button.md rename to apps/docs/docs/ui/back-button.md diff --git a/apps/docs/ui/main-button.md b/apps/docs/docs/ui/main-button.md similarity index 100% rename from apps/docs/ui/main-button.md rename to apps/docs/docs/ui/main-button.md diff --git a/apps/docs/ui/popup.md b/apps/docs/docs/ui/popup.md similarity index 100% rename from apps/docs/ui/popup.md rename to apps/docs/docs/ui/popup.md diff --git a/apps/docs/ui/settings-button.md b/apps/docs/docs/ui/settings-button.md similarity index 100% rename from apps/docs/ui/settings-button.md rename to apps/docs/docs/ui/settings-button.md diff --git a/apps/docs/packages/golang/init-data-golang.md b/apps/docs/packages/golang/init-data-golang.md index 96d4e6f45..a35080920 100644 --- a/apps/docs/packages/golang/init-data-golang.md +++ b/apps/docs/packages/golang/init-data-golang.md @@ -2,7 +2,7 @@ The package provides utilities to work with the initialization data of Telegram Mini Apps. To learn more about the initialization data and its usage, please refer to -the [documentation](../../launch-parameters/common-information.md). +the [documentation](../../docs/launch-parameters/common-information.md). ## Installation diff --git a/apps/docs/packages/typescript/tma-js-init-data-node.md b/apps/docs/packages/node/tma-js-init-data-node.md similarity index 89% rename from apps/docs/packages/typescript/tma-js-init-data-node.md rename to apps/docs/packages/node/tma-js-init-data-node.md index 9eca9c5f4..7840c8a62 100644 --- a/apps/docs/packages/typescript/tma-js-init-data-node.md +++ b/apps/docs/packages/node/tma-js-init-data-node.md @@ -8,10 +8,10 @@ The package provides utilities to work with the initialization data of Telegram Mini Apps on the server side. To learn more about the initialization data and its usage, please refer to -the [documentation](../../launch-parameters/common-information.md). +the [documentation](../../docs/launch-parameters/common-information.md). ::: info -This package extends the functionality of [@tma.js/init-data](tma-js-init-data/about.md), including all +This package extends the functionality of [@tma.js/init-data](../typescript/tma-js-init-data/about.md), including all its types and utilities. Therefore, there is no need to install both packages separately. ::: @@ -35,7 +35,7 @@ yarn add @tma.js/init-data-node ### Parsing -You can learn more about parsing utilities in [@tma.js/init-data](tma-js-init-data/about.md#parsing) +You can learn more about parsing utilities in [@tma.js/init-data](../typescript/tma-js-init-data/about.md#parsing) documentation. ### Validation diff --git a/apps/docs/packages/typescript/tma-js-init-data/about.md b/apps/docs/packages/typescript/tma-js-init-data/about.md index f76b8bd80..81fb9fcf1 100644 --- a/apps/docs/packages/typescript/tma-js-init-data/about.md +++ b/apps/docs/packages/typescript/tma-js-init-data/about.md @@ -8,7 +8,7 @@ The package provides utilities to work with the initialization data of Telegram Mini Apps on the client side. To learn more about the initialization data and its usage, please refer to -the [documentation](../../../launch-parameters/common-information.md). +the [documentation](../../../docs/launch-parameters/common-information.md). ## Installation @@ -72,5 +72,5 @@ to [InitData type](init-data.md) page. ## Validation We have moved the validation utilities to a -separate [TypeScript package](../tma-js-init-data-node.md). These utilities are only needed on the +separate [TypeScript package](../../node/tma-js-init-data-node.md). These utilities are only needed on the server side, as there is no need to validate initialization data on the client side.** diff --git a/apps/docs/packages/typescript/tma-js-launch-params.md b/apps/docs/packages/typescript/tma-js-launch-params.md index dc92b04d7..5d5137905 100644 --- a/apps/docs/packages/typescript/tma-js-launch-params.md +++ b/apps/docs/packages/typescript/tma-js-launch-params.md @@ -7,7 +7,7 @@ ![[npm-link]][npm-shield] Provides utilities to work with Telegram Mini -Apps [launch parameters](../../launch-parameters/common-information.md). +Apps [launch parameters](../../docs/launch-parameters/common-information.md). ## Installation diff --git a/apps/docs/packages/typescript/tma-js-sdk/about.md b/apps/docs/packages/typescript/tma-js-sdk/about.md index b3d7e5be5..cc7443ce6 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/about.md +++ b/apps/docs/packages/typescript/tma-js-sdk/about.md @@ -14,7 +14,7 @@ Mini Apps. It consists of several individual components, each responsible for a the Telegram Mini Apps ecosystem. Before you begin using the SDK, we highly recommend familiarizing yourself with the Telegram Mini -Apps [documentation](../../../about-platform.md) to grasp the fundamental concepts of the platform. +Apps [documentation](../../../docs/about-platform.md) to grasp the fundamental concepts of the platform. ## Installation @@ -123,7 +123,7 @@ reached, an error will be thrown. ## Launch parameters The launch parameters are the initial parameters passed to the Mini App. You can find more -information about them in the [documentation](../../../launch-parameters/common-information.md). +information about them in the [documentation](../../../docs/launch-parameters/common-information.md). Developers can retrieve the launch parameters by using the `retrieveLaunchParams` function. This function parses the parameters that begin with the `tgWebApp` prefix. diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/back-button.md b/apps/docs/packages/typescript/tma-js-sdk/components/back-button.md index 953f894c5..168c76b0f 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/back-button.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/back-button.md @@ -1,6 +1,6 @@ # `BackButton` -Controls the [Back Button](../../../../ui/back-button.md) displayed in the header of the Mini App in +Controls the [Back Button](../../../../docs/ui/back-button.md) displayed in the header of the Mini App in the Telegram interface. ## Initialization diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/closing-behaviour.md b/apps/docs/packages/typescript/tma-js-sdk/components/closing-behaviour.md index 7a4d5b708..19e8de93c 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/closing-behaviour.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/closing-behaviour.md @@ -1,7 +1,7 @@ # `ClosingBehaviour` Controls the application closing behavior. There is more information about this functionality in -this [documentation](../../../../functionality/closing-behavior.md). +this [documentation](../../../../docs/functionality/closing-behavior.md). ## Initialization diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/haptic-feedback.md b/apps/docs/packages/typescript/tma-js-sdk/components/haptic-feedback.md index e119721fe..6b02071ec 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/haptic-feedback.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/haptic-feedback.md @@ -2,7 +2,7 @@ Controls the haptic feedback. It allows calling different types of haptic notifications which usually occur after the user interaction with the application. There is more information about this -component in this [documentation](../../../../functionality/haptic-feedback.md). +component in this [documentation](../../../../docs/functionality/haptic-feedback.md). ## Initialization diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/init-data.md b/apps/docs/packages/typescript/tma-js-sdk/components/init-data.md index 2698c82ee..034216b44 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/init-data.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/init-data.md @@ -5,7 +5,7 @@ outline: [2, 3] # `InitData` The component which is responsible for displaying the Telegram Mini -Apps [init data](../../../../launch-parameters/init-data.md). This class represents object with +Apps [init data](../../../../docs/launch-parameters/init-data.md). This class represents object with readonly properties. To create its new instance, a developer could use the class constructor as follows: diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/main-button.md b/apps/docs/packages/typescript/tma-js-sdk/components/main-button.md index 6e2bf6fc1..de05b712e 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/main-button.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/main-button.md @@ -1,6 +1,6 @@ # `MainButton` -The component which controls the [Main Button](../../../../ui/main-button.md). +The component which controls the [Main Button](../../../../docs/ui/main-button.md). ## Initialization diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/popup.md b/apps/docs/packages/typescript/tma-js-sdk/components/popup.md index 34f93bd5a..d084bf9bb 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/popup.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/popup.md @@ -1,6 +1,6 @@ # `Popup` -The component which controls the currently displayed application [popup](../../../../ui/popup.md). +The component which controls the currently displayed application [popup](../../../../docs/ui/popup.md). ## Initialization diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/theme-params.md b/apps/docs/packages/typescript/tma-js-sdk/components/theme-params.md index 5428e45f7..8853041d5 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/theme-params.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/theme-params.md @@ -1,7 +1,7 @@ # `ThemeParams` The component which contains an information about currently -used [theme](../../../../functionality/theming.md) by the Telegram application. +used [theme](../../../../docs/functionality/theming.md) by the Telegram application. ## Initialization diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/viewport.md b/apps/docs/packages/typescript/tma-js-sdk/components/viewport.md index 8ac42c605..2e39a5573 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/viewport.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/viewport.md @@ -1,7 +1,7 @@ # `Viewport` The component which contains an information about the current Mini App -device [viewport](../../../../functionality/viewport.md), its dimensions and state. +device [viewport](../../../../docs/functionality/viewport.md), its dimensions and state. ## Initialization diff --git a/apps/docs/packages/typescript/tma-js-sdk/components/web-app.md b/apps/docs/packages/typescript/tma-js-sdk/components/web-app.md index bd40fcbd1..2f41be359 100644 --- a/apps/docs/packages/typescript/tma-js-sdk/components/web-app.md +++ b/apps/docs/packages/typescript/tma-js-sdk/components/web-app.md @@ -26,7 +26,7 @@ const webApp = new WebApp( ## Platform You could get current Telegram Mini -Apps [platform](../../../../about-platform.md#supported-applications) by getting `platform` +Apps [platform](../../../../docs/about-platform.md#supported-applications) by getting `platform` property. ## Opening links diff --git a/apps/docs/packages/typescript/tma-js-theme-params.md b/apps/docs/packages/typescript/tma-js-theme-params.md index c828e35cc..9282001a6 100644 --- a/apps/docs/packages/typescript/tma-js-theme-params.md +++ b/apps/docs/packages/typescript/tma-js-theme-params.md @@ -6,7 +6,7 @@ ![[npm-link]][npm-shield] -Provides utilities to work with Telegram Mini Apps [theme](../../functionality/theming.md). +Provides utilities to work with Telegram Mini Apps [theme](../../docs/functionality/theming.md). ## Installation diff --git a/apps/docs/platform/about-platform.md b/apps/docs/platform/about-platform.md new file mode 100644 index 000000000..2e0e5791d --- /dev/null +++ b/apps/docs/platform/about-platform.md @@ -0,0 +1,75 @@ +# About platform + +Telegram Mini Apps is a technology created by developers of the famous messenger Telegram. The main +it’s purpose is to provide developers more flexible communication channel with Telegram users. + +It may seem not clear, but Mini Apps are not self-served services. The first thing to note is, +technically, this technology is just an add-on for such already-known Telegram functionality as +Telegram Bots. So, currently, creating a Mini App without creating a Telegram Bot is not available. + +The platform offers a high variety of available methods to communicate with the Telegram application +to make your web applications look more native, allow them to simulate native application's +behavior, and, finally, **mimic** native applications. + +## Required technologies + +Before starting to create an application on the Mini Apps platform, it is important to know what +Mini Apps is from its technical side. This will lead the developer to language and technologies +selection. + +Internally, Mini Apps are usual web applications, which are displayed in WebView. In other words, +they are just a set of static files (mostly `.js`, `.css`, and `.html`). So, to create Mini App, it +is enough to learn standard front-end development technologies, such as: + +- JavaScript +- CSS +- HTML + +Really simple, isn't it? But to make much more serious and bigger applications, we recommend using +more solid technologies, such as `TypeScript`, `React`, `SCSS`, etc. + +So, if we want to create Mini App, we should create a standard web application with any technologies +stack. The only 1 thing Telegram needs from the developer is the application URL to download it +from. It will be used as a source for WebView, which will lead to application download and display. + +## Usage + +As we mentioned in the previous section, Mini Apps are add-ons for Telegram Bots. Telegram Bots is +also known technology that provides functionality for a wide list of use cases. You could create a +bot to buy a ticket in the cinema, make him tell user jokes, generate random numbers, etc. In other +words, the bot can do whatever the developer thinks about. + +The problem is, the visual part of bots is not as good and functional as it could be. Their current +implementation is "console-like" which is more appropriate for developers, not common users. That's +the time for Mini Apps to show up. + +Using Mini Apps, developers are allowed to create more user-friendly and complex interfaces, which +are commonly used by usual users. With this technology, the developer is still able to communicate +with the bot behind Mini App, but, additionally, he can provide some more flexible interfaces to +interact with. + +Mini Apps are usually used when a standard bot interface is not enough. Create a Mini App when you +want to make user life easier when displaying several buttons is not even close to the +functionality, you want to provide. + +## Supported applications + +Currently, Telegram Mini Apps is presented on the wide list of Telegram +applications: + +- [Telegram for Android](https://github.com/DrKLO/Telegram) `android`; +- [Telegram for iOS](https://github.com/TelegramMessenger/Telegram-iOS) `ios`; +- [Telegram for macOS](https://github.com/overtake/TelegramSwift) `macos`; +- [Telegram Desktop](https://github.com/telegramdesktop/tdesktop) `tdesktop`; +- [Telegram Web A](https://github.com/Ajaxy/telegram-tt) `web`; +- [Telegram Web K](https://github.com/morethanwords/tweb) `webk`; + +Other applications either don't have implementation for Telegram Mini Apps, or +support it too poorly. This will probably be useful in the next sections of the +documentation. + +::: info +As long as all applications are being developed separately, there may be variations in how they +implement the platform. If you encounter unexpected differences, please consider reporting +an [issue](https://github.com/Telegram-Mini-Apps/issues). +::: diff --git a/apps/docs/platform/apps-communication/events.md b/apps/docs/platform/apps-communication/events.md new file mode 100644 index 000000000..92eb49f02 --- /dev/null +++ b/apps/docs/platform/apps-communication/events.md @@ -0,0 +1,254 @@ +--- +outline: [2, 3] +--- + +# Events + +Events are signals, sent from Telegram native application in case, when some external action was +done. Like methods, each event has its unique name and parameters. + +## Web + +As mentioned before, the web version uses a standard way of communication between iframes. It means, +the parent iframe is able to send events through `window.postMessage` function. To handle this type +of message, it is enough to add `message` event listener on the global `window` object: + +```typescript +window.addEventListener('message', ...); +``` + +The native application will send an event with `data: string` which represents a JSON object +converted to string. This object has the same interface as we defined in +the [Methods](methods.md#web) section: + +```typescript +interface MessageJSON { + eventType: string; + eventData: any; +} +``` + +Then, lets imagine how we could process an event from Telegram application: + +```typescript +window.addEventListener('message', ({ data }) => { + const { eventType, eventData } = JSON.parse(data); + console.log(eventType, eventData); +}); +``` + +::: warning +In this code, we assumed, that the `message` event is sent only by the native application which is +not always true in real applications. Additionally, we didn't check if `data` is really of +type `string`. Don't forget to check each type and appropriately process incoming events. +::: + +## Desktop, mobile and Windows Phone + +Desktop, mobile, and Windows Phone versions of Telegram don’t use the method, described in the +previous section. They do it in a bit unusual way. The first thing developer should know, is in +case, when Telegram needs to emit an event, it will insert JavaScript code, which calls a globally +defined function. + +Here is an example: + +```typescript +window.Telegram.WebView.receiveEvent('popup_closed', { button_id: 'cancel' }); +``` + +Path to this function depends on platform: + +- `window.TelegramGameProxy.receiveEvent` - Telegram Desktop; +- `window.Telegram.WebView.receiveEvent` - Telegram for iOS and Android; +- `window.TelegramGameProxy_receiveEvent` - Windows Phone + +All of these functions have the same signature: + +```typescript +type ReceiveEvent = (eventType: string, eventData: unknown) => void; +``` + +So, the solution is rather simple. To handle incoming events we should create a function of this +type and assign it to all 3 paths. + +## Available events + +This section contains the list of events, sent from Telegram: their names, description, and +parameters. Section title means minimal version, from which events inside the section could be sent. + +### `back_button_pressed` + +Available since: **v6.1** + +User clicked the [Back Button](../ui/back-button.md). + +### `clipboard_text_received` + +Available since: **v6.4** + +Telegram application attempted to extract text from clipboard. + +| Field | Type | Description | +|--------|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------| +| req_id | `string` | Passed during the [web_app_read_text_from_clipboard](methods.md#web-app-read-text-from-clipboard) method invocation `req_id` value. | +| data | `string` or `null` | _Optional_. Data extracted from the clipboard. The returned value will have the type `string` only in the case, application has access to the clipboard. | + +### `custom_method_invoked` + +Available since: **v6.9** + +Custom method invocation completed. + +| Field | Type | Description | +|--------|-----------|--------------------------------------------------| +| req_id | `string` | Unique identifier of this invocation. | +| result | `unknown` | _Optional_. Method invocation successful result. | +| error | `string` | _Optional_. Method invocation error code. | + +### `invoice_closed` + +An invoice was closed. + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldTypeDescription
slug + string + + Passed during the  + + web_app_open_invoice +   + method invocation slug value. +
status + string + + Invoice status. Values: +
    +
  • + paid, invoice was paid +
  • +
  • + failed, invoice failed +
  • +
  • + pending, invoice is currently pending +
  • +
  • + cancelled, invoice was cancelled +
  • +
+
+ +### `main_button_pressed` + +User clicked the [Main Button](../ui/main-button.md). + +### `phone_requested` + +Available since: **v6.9** + +Application received phone access request status. + +| Field | Type | Description | +|--------|----------|-------------------------------------| +| status | `string` | Request status. Can only be `sent`. | + +### `popup_closed` + +[Popup](../ui/popup.md) was closed. + +| Field | Type | Description | +|-----------|----------|-----------------------------------------------------------------------------------------------------------------------------------------| +| button_id | `string` | _Optional_. Identifier of the clicked button. In case, the popup was closed without clicking any button, this property will be omitted. | + +### `reload_iframe` + +Parent iframe requested current iframe reload. + +### `qr_text_received` + +Available since: **v6.4** + +The QR scanner scanned some QR and extracted its content. + +| Field | Type | Description | +|-------|----------|-----------------------------------------| +| data | `string` | _Optional_. Data extracted from the QR. | + +### `scan_qr_popup_closed` + +Available since: **v6.4** + +QR scanner was closed. + +### `set_custom_style` + +The event which is usually sent by the Telegram web application. Its payload represents `