@tma.js/sdk 1.4.4 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/dts/bridge/events/events.d.ts +16 -16
- package/dist/dts/bridge/methods/methods.d.ts +27 -27
- package/dist/dts/bridge/methods/popup.d.ts +1 -1
- package/dist/dts/init-data/types.d.ts +3 -3
- package/dist/dts/launch-params/types.d.ts +1 -1
- package/dist/dts/theme-params/types.d.ts +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.iife.js +0 -1
- package/dist/index.mjs +0 -1
- package/package.json +2 -3
- package/dist/index.cjs.map +0 -1
- package/dist/index.iife.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/src/__tests__/globals.ts +0 -39
- package/src/back-button/BackButton.ts +0 -90
- package/src/back-button/__tests__/BackButton.ts +0 -129
- package/src/back-button/index.ts +0 -2
- package/src/back-button/types.ts +0 -14
- package/src/bridge/__tests__/parseMessage.ts +0 -23
- package/src/bridge/__tests__/request.ts +0 -236
- package/src/bridge/env/__tests__/hasExternalNotify.ts +0 -15
- package/src/bridge/env/__tests__/hasWebviewProxy.ts +0 -15
- package/src/bridge/env/__tests__/isIframe.ts +0 -30
- package/src/bridge/env/hasExternalNotify.ts +0 -19
- package/src/bridge/env/hasWebviewProxy.ts +0 -19
- package/src/bridge/env/index.ts +0 -3
- package/src/bridge/env/isIframe.ts +0 -11
- package/src/bridge/errors/MethodUnsupportedError.ts +0 -13
- package/src/bridge/errors/ParameterUnsupportedError.ts +0 -13
- package/src/bridge/errors/index.ts +0 -2
- package/src/bridge/events/__tests__/createEmitter.ts +0 -143
- package/src/bridge/events/__tests__/off.ts +0 -34
- package/src/bridge/events/__tests__/on.ts +0 -49
- package/src/bridge/events/__tests__/onTelegramEvent.ts +0 -49
- package/src/bridge/events/__tests__/once.ts +0 -64
- package/src/bridge/events/__tests__/singletonEmitter.ts +0 -22
- package/src/bridge/events/__tests__/subscribe.ts +0 -49
- package/src/bridge/events/__tests__/unsubscribe.ts +0 -34
- package/src/bridge/events/createEmitter.ts +0 -108
- package/src/bridge/events/events.ts +0 -170
- package/src/bridge/events/index.ts +0 -9
- package/src/bridge/events/off.ts +0 -14
- package/src/bridge/events/on.ts +0 -19
- package/src/bridge/events/onTelegramEvent.ts +0 -81
- package/src/bridge/events/once.ts +0 -18
- package/src/bridge/events/parsers/__tests__/clipboardTextReceived.ts +0 -21
- package/src/bridge/events/parsers/__tests__/invoiceClosed.ts +0 -12
- package/src/bridge/events/parsers/__tests__/popupClosed.ts +0 -10
- package/src/bridge/events/parsers/__tests__/qrTextReceived.ts +0 -9
- package/src/bridge/events/parsers/__tests__/theme-changed.ts +0 -42
- package/src/bridge/events/parsers/__tests__/viewportChanged.ts +0 -49
- package/src/bridge/events/parsers/clipboardTextReceived.ts +0 -26
- package/src/bridge/events/parsers/customMethodInvoked.ts +0 -25
- package/src/bridge/events/parsers/index.ts +0 -9
- package/src/bridge/events/parsers/invoiceClosed.ts +0 -26
- package/src/bridge/events/parsers/phoneRequested.ts +0 -14
- package/src/bridge/events/parsers/popupClosed.ts +0 -19
- package/src/bridge/events/parsers/qrTextReceived.ts +0 -14
- package/src/bridge/events/parsers/theme-changed.ts +0 -58
- package/src/bridge/events/parsers/viewportChanged.ts +0 -33
- package/src/bridge/events/parsers/writeAccessRequested.ts +0 -14
- package/src/bridge/events/singletonEmitter.ts +0 -19
- package/src/bridge/events/subscribe.ts +0 -15
- package/src/bridge/events/unsubscribe.ts +0 -10
- package/src/bridge/index.ts +0 -7
- package/src/bridge/invokeCustomMethod.ts +0 -56
- package/src/bridge/methods/__tests__/createPostEvent.ts +0 -37
- package/src/bridge/methods/__tests__/postEvent.ts +0 -137
- package/src/bridge/methods/createPostEvent.ts +0 -40
- package/src/bridge/methods/custom-methods.ts +0 -68
- package/src/bridge/methods/haptic.ts +0 -52
- package/src/bridge/methods/index.ts +0 -6
- package/src/bridge/methods/methods.ts +0 -370
- package/src/bridge/methods/popup.ts +0 -53
- package/src/bridge/methods/postEvent.ts +0 -101
- package/src/bridge/parseMessage.ts +0 -28
- package/src/bridge/request.ts +0 -176
- package/src/classnames/__tests__/classNames.ts +0 -20
- package/src/classnames/__tests__/mergeClassNames.ts +0 -21
- package/src/classnames/classNames.ts +0 -34
- package/src/classnames/index.ts +0 -2
- package/src/classnames/mergeClassNames.ts +0 -60
- package/src/closing-behavior/ClosingBehavior.ts +0 -64
- package/src/closing-behavior/__tests__/ClosingBehavior.ts +0 -86
- package/src/closing-behavior/index.ts +0 -2
- package/src/closing-behavior/types.ts +0 -12
- package/src/cloud-storage/CloudStorage.ts +0 -138
- package/src/cloud-storage/index.ts +0 -1
- package/src/colors/__tests__/isColorDark.ts +0 -12
- package/src/colors/__tests__/isRGB.ts +0 -13
- package/src/colors/__tests__/isRGBShort.ts +0 -13
- package/src/colors/__tests__/toRGB.ts +0 -23
- package/src/colors/index.ts +0 -5
- package/src/colors/isColorDark.ts +0 -22
- package/src/colors/isRGB.ts +0 -9
- package/src/colors/isRGBShort.ts +0 -9
- package/src/colors/toRGB.ts +0 -49
- package/src/colors/types.ts +0 -9
- package/src/css/__tests__/bindMiniAppCSSVars.ts +0 -175
- package/src/css/__tests__/bindThemeCSSVars.ts +0 -52
- package/src/css/__tests__/bindViewportCSSVars.ts +0 -55
- package/src/css/__tests__/setCSSVar.ts +0 -14
- package/src/css/bindMiniAppCSSVars.ts +0 -51
- package/src/css/bindThemeCSSVars.ts +0 -31
- package/src/css/bindViewportCSSVars.ts +0 -36
- package/src/css/index.ts +0 -4
- package/src/css/setCSSVar.ts +0 -8
- package/src/event-emitter/EventEmitter.ts +0 -146
- package/src/event-emitter/__tests__/EventEmitter.ts +0 -145
- package/src/event-emitter/index.ts +0 -2
- package/src/event-emitter/types.ts +0 -60
- package/src/globals.ts +0 -38
- package/src/haptic-feedback/HapticFeedback.ts +0 -70
- package/src/haptic-feedback/__tests__/HapticFeedback.ts +0 -68
- package/src/haptic-feedback/index.ts +0 -1
- package/src/index.ts +0 -185
- package/src/init/catchCustomStyles.ts +0 -17
- package/src/init/creators/__tests__/createViewport.ts +0 -96
- package/src/init/creators/createBackButton.ts +0 -25
- package/src/init/creators/createClosingBehavior.ts +0 -24
- package/src/init/creators/createMainButton.ts +0 -51
- package/src/init/creators/createMiniApp.ts +0 -48
- package/src/init/creators/createRequestIdGenerator.ts +0 -13
- package/src/init/creators/createSettingsButton.ts +0 -25
- package/src/init/creators/createThemeParams.ts +0 -11
- package/src/init/creators/createViewport.ts +0 -94
- package/src/init/creators/index.ts +0 -8
- package/src/init/css/index.ts +0 -1
- package/src/init/css/processCSSVarsOption.ts +0 -55
- package/src/init/index.ts +0 -2
- package/src/init/init.ts +0 -134
- package/src/init/types.ts +0 -94
- package/src/init-data/InitData.ts +0 -96
- package/src/init-data/__tests__/InitData.ts +0 -98
- package/src/init-data/__tests__/chatParser.ts +0 -102
- package/src/init-data/__tests__/initDataParser.ts +0 -136
- package/src/init-data/__tests__/parseInitData.ts +0 -136
- package/src/init-data/__tests__/userParser.ts +0 -96
- package/src/init-data/chatParser.ts +0 -19
- package/src/init-data/index.ts +0 -6
- package/src/init-data/initDataParser.ts +0 -41
- package/src/init-data/parseInitData.ts +0 -10
- package/src/init-data/types.ts +0 -164
- package/src/init-data/userParser.ts +0 -45
- package/src/invoice/Invoice.ts +0 -123
- package/src/invoice/index.ts +0 -2
- package/src/invoice/types.ts +0 -11
- package/src/launch-params/__tests__/retrieveFromUrl.ts +0 -19
- package/src/launch-params/computeLaunchData.ts +0 -81
- package/src/launch-params/computePageReload.ts +0 -13
- package/src/launch-params/getFirstNavigationEntry.ts +0 -10
- package/src/launch-params/index.ts +0 -13
- package/src/launch-params/launchParamsParser.ts +0 -45
- package/src/launch-params/parseLaunchParams.ts +0 -10
- package/src/launch-params/retrieveCurrent.ts +0 -27
- package/src/launch-params/retrieveFromLocation.ts +0 -10
- package/src/launch-params/retrieveFromPerformance.ts +0 -18
- package/src/launch-params/retrieveFromUrl.ts +0 -19
- package/src/launch-params/retrieveLaunchData.ts +0 -30
- package/src/launch-params/serializeLaunchParams.ts +0 -37
- package/src/launch-params/storage.ts +0 -33
- package/src/launch-params/types.ts +0 -62
- package/src/logger/Logger.ts +0 -72
- package/src/logger/__tests__/Logger.ts +0 -107
- package/src/logger/index.ts +0 -1
- package/src/main-button/MainButton.ts +0 -239
- package/src/main-button/__tests__/MainButton.ts +0 -346
- package/src/main-button/index.ts +0 -2
- package/src/main-button/types.ts +0 -26
- package/src/mini-app/MiniApp.ts +0 -348
- package/src/mini-app/__tests__/MiniApp.ts +0 -140
- package/src/mini-app/contactParser.ts +0 -29
- package/src/mini-app/index.ts +0 -2
- package/src/mini-app/types.ts +0 -38
- package/src/misc/__tests__/isRecord.ts +0 -21
- package/src/misc/index.ts +0 -2
- package/src/misc/isRecord.ts +0 -7
- package/src/misc/isTMA.ts +0 -13
- package/src/navigation/HashNavigator/HashNavigator.ts +0 -220
- package/src/navigation/HashNavigator/__tests__/HashNavigator.ts +0 -144
- package/src/navigation/HashNavigator/__tests__/drop.ts +0 -42
- package/src/navigation/HashNavigator/__tests__/go.ts +0 -9
- package/src/navigation/HashNavigator/drop.ts +0 -36
- package/src/navigation/HashNavigator/go.ts +0 -28
- package/src/navigation/HashNavigator/index.ts +0 -2
- package/src/navigation/HashNavigator/types.ts +0 -41
- package/src/navigation/Navigator/Navigator.ts +0 -282
- package/src/navigation/Navigator/index.ts +0 -2
- package/src/navigation/Navigator/types.ts +0 -55
- package/src/navigation/ensurePrefix.ts +0 -9
- package/src/navigation/getHash.ts +0 -17
- package/src/navigation/index.ts +0 -4
- package/src/parsing/ArrayValueParser.ts +0 -79
- package/src/parsing/ParseError.ts +0 -27
- package/src/parsing/ParseSchemaFieldError.ts +0 -21
- package/src/parsing/ValueParser.ts +0 -71
- package/src/parsing/__tests__/ArrayValueParser.ts +0 -18
- package/src/parsing/__tests__/toRecord.ts +0 -10
- package/src/parsing/createValueParserGenerator.ts +0 -16
- package/src/parsing/index.ts +0 -10
- package/src/parsing/parseBySchema.ts +0 -65
- package/src/parsing/parsers/__tests__/array.ts +0 -39
- package/src/parsing/parsers/__tests__/boolean.ts +0 -31
- package/src/parsing/parsers/__tests__/date.ts +0 -25
- package/src/parsing/parsers/__tests__/json.ts +0 -80
- package/src/parsing/parsers/__tests__/number.ts +0 -23
- package/src/parsing/parsers/__tests__/rgb.ts +0 -22
- package/src/parsing/parsers/__tests__/searchParams.ts +0 -105
- package/src/parsing/parsers/__tests__/string.ts +0 -25
- package/src/parsing/parsers/array.ts +0 -9
- package/src/parsing/parsers/boolean.ts +0 -22
- package/src/parsing/parsers/date.ts +0 -11
- package/src/parsing/parsers/index.ts +0 -8
- package/src/parsing/parsers/json.ts +0 -17
- package/src/parsing/parsers/number.ts +0 -21
- package/src/parsing/parsers/rgb.ts +0 -10
- package/src/parsing/parsers/searchParams.ts +0 -24
- package/src/parsing/parsers/string.ts +0 -12
- package/src/parsing/toRecord.ts +0 -27
- package/src/parsing/types.ts +0 -32
- package/src/parsing/unexpectedTypeError.ts +0 -6
- package/src/popup/Popup.ts +0 -91
- package/src/popup/__tests__/Popup.ts +0 -130
- package/src/popup/__tests__/preparePopupParams.ts +0 -85
- package/src/popup/index.ts +0 -2
- package/src/popup/preparePopupParams.ts +0 -59
- package/src/popup/types.ts +0 -69
- package/src/qr-scanner/QRScanner.ts +0 -95
- package/src/qr-scanner/index.ts +0 -2
- package/src/qr-scanner/types.ts +0 -11
- package/src/settings-button/SettingsButton.ts +0 -85
- package/src/settings-button/index.ts +0 -2
- package/src/settings-button/types.ts +0 -15
- package/src/state/State.ts +0 -67
- package/src/state/index.ts +0 -2
- package/src/state/types.ts +0 -31
- package/src/storage.ts +0 -69
- package/src/supports/__tests__/supports.ts +0 -123
- package/src/supports/createSupportsFunc.ts +0 -18
- package/src/supports/createSupportsParamFunc.ts +0 -27
- package/src/supports/index.ts +0 -4
- package/src/supports/supports.ts +0 -84
- package/src/supports/types.ts +0 -1
- package/src/theme-params/ThemeParams.ts +0 -131
- package/src/theme-params/__tests__/keys.ts +0 -19
- package/src/theme-params/__tests__/parseThemeParams.ts +0 -29
- package/src/theme-params/__tests__/serializeThemeParams.ts +0 -29
- package/src/theme-params/__tests__/themeParamsParser.ts +0 -29
- package/src/theme-params/index.ts +0 -6
- package/src/theme-params/keys.ts +0 -24
- package/src/theme-params/parseThemeParams.ts +0 -10
- package/src/theme-params/requestThemeParams.ts +0 -13
- package/src/theme-params/serializeThemeParams.ts +0 -20
- package/src/theme-params/themeParamsParser.ts +0 -22
- package/src/theme-params/types.ts +0 -33
- package/src/timeout/TimeoutError.ts +0 -6
- package/src/timeout/__tests__/isTimeoutError.ts +0 -9
- package/src/timeout/__tests__/withTimeout.ts +0 -28
- package/src/timeout/index.ts +0 -4
- package/src/timeout/isTimeoutError.ts +0 -9
- package/src/timeout/sleep.ts +0 -10
- package/src/timeout/withTimeout.ts +0 -24
- package/src/types/index.ts +0 -4
- package/src/types/methods.ts +0 -18
- package/src/types/platform.ts +0 -14
- package/src/types/request-id.ts +0 -10
- package/src/types/utils.ts +0 -50
- package/src/utils/Utils.ts +0 -107
- package/src/utils/index.ts +0 -1
- package/src/version/__tests__/compareVersions.ts +0 -19
- package/src/version/compareVersions.ts +0 -28
- package/src/version/index.ts +0 -2
- package/src/version/types.ts +0 -4
- package/src/viewport/Viewport.ts +0 -171
- package/src/viewport/__tests__/isStableViewportPlatform.ts +0 -15
- package/src/viewport/__tests__/utils.ts +0 -12
- package/src/viewport/index.ts +0 -4
- package/src/viewport/isStableViewportPlatform.ts +0 -10
- package/src/viewport/requestViewport.ts +0 -23
- package/src/viewport/types.ts +0 -23
- package/src/viewport/utils.ts +0 -7
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
import type { RGB } from '~/colors/index.js';
|
|
2
|
-
import type { IsNever, Not, RequestId, UnionKeys } from '~/types/index.js';
|
|
3
|
-
|
|
4
|
-
import type { AnyInvokeCustomMethodParams } from './custom-methods.js';
|
|
5
|
-
import type { AnyHapticFeedbackParams } from './haptic.js';
|
|
6
|
-
import type { PopupParams } from './popup.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Color key which could be used to update header color.
|
|
10
|
-
*/
|
|
11
|
-
export type HeaderColorKey = 'bg_color' | 'secondary_bg_color';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Chat type which could be used when calling `web_app_switch_inline_query` method.
|
|
15
|
-
*/
|
|
16
|
-
export type SwitchInlineQueryChatType = 'users' | 'bots' | 'groups' | 'channels';
|
|
17
|
-
|
|
18
|
-
interface CreateParams<Params = undefined, VersionedParam extends UnionKeys<Params> = never> {
|
|
19
|
-
params: Params;
|
|
20
|
-
versionedParams: VersionedParam;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Describes list of events and their parameters that could be posted by Bridge.
|
|
25
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods
|
|
26
|
-
*/
|
|
27
|
-
export interface MiniAppsMethods {
|
|
28
|
-
/**
|
|
29
|
-
* Notifies parent iframe about the current frame is ready. This method is only used in the Web
|
|
30
|
-
* version of Telegram. As a result, Mini App will receive `set_custom_style` event.
|
|
31
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#iframe-ready
|
|
32
|
-
*/
|
|
33
|
-
iframe_ready: CreateParams<{
|
|
34
|
-
/**
|
|
35
|
-
* True, if current Mini App supports native reloading.
|
|
36
|
-
*/
|
|
37
|
-
reload_supported?: boolean;
|
|
38
|
-
} | undefined>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Notifies parent iframe about the current iframe is going to reload.
|
|
42
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#iframe-will-reload
|
|
43
|
-
*/
|
|
44
|
-
iframe_will_reload: CreateParams;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Closes Mini App.
|
|
48
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-close
|
|
49
|
-
*/
|
|
50
|
-
web_app_close: CreateParams;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Closes a QR scanner. The Telegram application creates `scan_qr_popup_closed` event.
|
|
54
|
-
* @since v6.4
|
|
55
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-close-scan-qr-popup
|
|
56
|
-
*/
|
|
57
|
-
web_app_close_scan_qr_popup: CreateParams;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Sends data to the bot. When this method is called, a service message is sent to the bot
|
|
61
|
-
* containing the data of the length up to 4096 bytes. Then, Mini App will be closed.
|
|
62
|
-
*
|
|
63
|
-
* To get more information, take a look at `web_app_data` field in the
|
|
64
|
-
* class [Message](https://core.telegram.org/bots/api#message).
|
|
65
|
-
*
|
|
66
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-data-send
|
|
67
|
-
*/
|
|
68
|
-
web_app_data_send: CreateParams<{
|
|
69
|
-
/**
|
|
70
|
-
* Data to send to a bot. Should not have size of more than 4096 bytes.
|
|
71
|
-
*/
|
|
72
|
-
data: string;
|
|
73
|
-
}>;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Expands the Mini App.
|
|
77
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-expand
|
|
78
|
-
*/
|
|
79
|
-
web_app_expand: CreateParams;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Invokes custom method.
|
|
83
|
-
* @since v6.9
|
|
84
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-invoke-custom-method
|
|
85
|
-
*/
|
|
86
|
-
web_app_invoke_custom_method: CreateParams<AnyInvokeCustomMethodParams>;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Opens an invoice by its specified slug. More information about invoices in
|
|
90
|
-
* this [documentation](https://core.telegram.org/bots/payments).
|
|
91
|
-
* @since v6.1
|
|
92
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-invoice
|
|
93
|
-
*/
|
|
94
|
-
web_app_open_invoice: CreateParams<{
|
|
95
|
-
/**
|
|
96
|
-
* Invoice unique identifier.
|
|
97
|
-
*/
|
|
98
|
-
slug: string;
|
|
99
|
-
}>;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Opens link in the default browser. Mini App will not be closed.
|
|
103
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-link
|
|
104
|
-
*/
|
|
105
|
-
web_app_open_link: CreateParams<{
|
|
106
|
-
/**
|
|
107
|
-
* URL to be opened by Telegram application. Should be a full path with `https` protocol.
|
|
108
|
-
*/
|
|
109
|
-
url: string;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Link will be opened in Instant View mode if possible.
|
|
113
|
-
* @since v6.4
|
|
114
|
-
* @see https://instantview.telegram.org/
|
|
115
|
-
*/
|
|
116
|
-
try_instant_view?: boolean;
|
|
117
|
-
}, 'try_instant_view'>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Opens a new popup. When user closes the popup, Telegram creates the `popup_closed` event.
|
|
121
|
-
* @since v6.2
|
|
122
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-popup
|
|
123
|
-
*/
|
|
124
|
-
web_app_open_popup: CreateParams<PopupParams>;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Opens a QR scanner. When the scanner was closed, the Telegram application creates
|
|
128
|
-
* the `scan_qr_popup_closed` event. When the scanner reads QR, Telegram creates the
|
|
129
|
-
* `qr_text_received` event.
|
|
130
|
-
* @since v6.4
|
|
131
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-scan-qr-popup
|
|
132
|
-
*/
|
|
133
|
-
web_app_open_scan_qr_popup: CreateParams<{
|
|
134
|
-
/**
|
|
135
|
-
* Text to be displayed in the QR scanner.
|
|
136
|
-
*/
|
|
137
|
-
text?: string;
|
|
138
|
-
}>;
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Opens the Telegram link by its pathname and query parameters. The link will be opened in the
|
|
142
|
-
* Telegram app, Mini App will be closed.
|
|
143
|
-
* @since v6.1
|
|
144
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-tg-link
|
|
145
|
-
*/
|
|
146
|
-
web_app_open_tg_link: CreateParams<{
|
|
147
|
-
/**
|
|
148
|
-
* Should be a value taken from the link of this format: `https://t.me/{path_full}`. Can
|
|
149
|
-
* additionally contain query parameters.
|
|
150
|
-
*/
|
|
151
|
-
path_full: string;
|
|
152
|
-
}>;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Reads text from the clipboard. The method accepts a request identifier which is used to
|
|
156
|
-
* appropriately retrieve the method execution result from the `clipboard_text_received` event.
|
|
157
|
-
* @since v6.4
|
|
158
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-read-text-from-clipboard
|
|
159
|
-
*/
|
|
160
|
-
web_app_read_text_from_clipboard: CreateParams<{
|
|
161
|
-
/**
|
|
162
|
-
* Unique request identifier. Should be any unique string to handle the generated event
|
|
163
|
-
* appropriately.
|
|
164
|
-
*/
|
|
165
|
-
req_id: RequestId;
|
|
166
|
-
}>;
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Notifies Telegram about current application is ready to be shown. This method will make
|
|
170
|
-
* Telegram to remove application loader and display Mini App.
|
|
171
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-ready
|
|
172
|
-
*/
|
|
173
|
-
web_app_ready: CreateParams;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Requests access to current user's phone.
|
|
177
|
-
* @since v6.9
|
|
178
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-phone
|
|
179
|
-
*/
|
|
180
|
-
web_app_request_phone: CreateParams;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Requests current theme from Telegram. As a result, Telegram will create `theme_changed` event.
|
|
184
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-theme
|
|
185
|
-
*/
|
|
186
|
-
web_app_request_theme: CreateParams;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Requests current viewport information from Telegram. As a result, Telegram will create
|
|
190
|
-
* `viewport_changed` event.
|
|
191
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-viewport
|
|
192
|
-
*/
|
|
193
|
-
web_app_request_viewport: CreateParams;
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Requests write message access to current user.
|
|
197
|
-
* @since v6.9
|
|
198
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-rqeuest-write-access
|
|
199
|
-
*/
|
|
200
|
-
web_app_request_write_access: CreateParams;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Updates the Mini App background color.
|
|
204
|
-
* @since v6.1
|
|
205
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-set-background-color
|
|
206
|
-
*/
|
|
207
|
-
web_app_set_background_color: CreateParams<{
|
|
208
|
-
/**
|
|
209
|
-
* The Mini App background color in `#RRGGBB` format.
|
|
210
|
-
*/
|
|
211
|
-
color: RGB;
|
|
212
|
-
}>;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Updates the Mini App header color.
|
|
216
|
-
* @since v6.1
|
|
217
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-set-header-color
|
|
218
|
-
*/
|
|
219
|
-
web_app_set_header_color: CreateParams<
|
|
220
|
-
| {
|
|
221
|
-
/**
|
|
222
|
-
* The Mini App header color key.
|
|
223
|
-
*/
|
|
224
|
-
color_key: HeaderColorKey
|
|
225
|
-
}
|
|
226
|
-
| {
|
|
227
|
-
/**
|
|
228
|
-
* Color in RGB format.
|
|
229
|
-
* @since v6.9
|
|
230
|
-
*/
|
|
231
|
-
color: RGB;
|
|
232
|
-
}, 'color'>;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Updates the Back Button settings.
|
|
236
|
-
* @since v6.1
|
|
237
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-back-button
|
|
238
|
-
*/
|
|
239
|
-
web_app_setup_back_button: CreateParams<{
|
|
240
|
-
/**
|
|
241
|
-
* Should the Back Button be visible.
|
|
242
|
-
*/
|
|
243
|
-
is_visible: boolean;
|
|
244
|
-
}>;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Updates current closing behavior.
|
|
248
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-closing-behavior
|
|
249
|
-
*/
|
|
250
|
-
web_app_setup_closing_behavior: CreateParams<{
|
|
251
|
-
/**
|
|
252
|
-
* Will user be prompted in case, an application is going to be closed.
|
|
253
|
-
*/
|
|
254
|
-
need_confirmation: boolean;
|
|
255
|
-
}>;
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Updates the Main Button settings.
|
|
259
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-main-button
|
|
260
|
-
*/
|
|
261
|
-
web_app_setup_main_button: CreateParams<{
|
|
262
|
-
/**
|
|
263
|
-
* Should the Main Button be displayed.
|
|
264
|
-
*/
|
|
265
|
-
is_visible?: boolean;
|
|
266
|
-
/**
|
|
267
|
-
* Should the Main Button be enabled.
|
|
268
|
-
*/
|
|
269
|
-
is_active?: boolean;
|
|
270
|
-
/**
|
|
271
|
-
* Should loader inside the Main Button be displayed. Use this property in case, some
|
|
272
|
-
* operation takes time. This loader will make user notified about it.
|
|
273
|
-
*/
|
|
274
|
-
is_progress_visible?: boolean;
|
|
275
|
-
/**
|
|
276
|
-
* Text inside the Main Button.
|
|
277
|
-
*/
|
|
278
|
-
text?: string;
|
|
279
|
-
/**
|
|
280
|
-
* The Main Button background color in `#RRGGBB` format.
|
|
281
|
-
*/
|
|
282
|
-
color?: string;
|
|
283
|
-
/**
|
|
284
|
-
* The Main Button text color in `#RRGGBB` format.
|
|
285
|
-
*/
|
|
286
|
-
text_color?: string;
|
|
287
|
-
}>;
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Updates current state of Settings Button.
|
|
291
|
-
* @since v6.10
|
|
292
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-settings-button
|
|
293
|
-
*/
|
|
294
|
-
web_app_setup_settings_button: CreateParams<{
|
|
295
|
-
/**
|
|
296
|
-
* Should the Settings Button be displayed.
|
|
297
|
-
*/
|
|
298
|
-
is_visible: boolean;
|
|
299
|
-
}>;
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Inserts the bot's username and the specified inline query in the current chat's input field.
|
|
303
|
-
* Query may be empty, in which case only the bot's username will be inserted. The client prompts
|
|
304
|
-
* the user to choose a specific chat, then opens that chat and inserts the bot's username and
|
|
305
|
-
* the specified inline query in the input field.
|
|
306
|
-
* @since v6.7
|
|
307
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-switch-inline-query
|
|
308
|
-
*/
|
|
309
|
-
web_app_switch_inline_query: CreateParams<{
|
|
310
|
-
/**
|
|
311
|
-
* Text which should be inserted in the input after the current bot name. Max length is
|
|
312
|
-
* 256 symbols.
|
|
313
|
-
*/
|
|
314
|
-
query: string;
|
|
315
|
-
/**
|
|
316
|
-
* List of chat types which could be chosen to send the message. Could be empty list.
|
|
317
|
-
*/
|
|
318
|
-
chat_types: SwitchInlineQueryChatType[];
|
|
319
|
-
}>;
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Generates haptic feedback event.
|
|
323
|
-
* @since v6.1
|
|
324
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-trigger-haptic-feedback
|
|
325
|
-
*/
|
|
326
|
-
web_app_trigger_haptic_feedback: CreateParams<AnyHapticFeedbackParams>;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Any Telegram Mini Apps known method name.
|
|
331
|
-
*/
|
|
332
|
-
export type MiniAppsMethodName = keyof MiniAppsMethods;
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Returns parameters for specified post-available event.
|
|
336
|
-
*/
|
|
337
|
-
export type MiniAppsMethodParams<M extends MiniAppsMethodName> = MiniAppsMethods[M]['params'];
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* True if specified method accepts parameters.
|
|
341
|
-
*/
|
|
342
|
-
export type MiniAppsMethodAcceptParams<M extends MiniAppsMethodName> =
|
|
343
|
-
Not<IsNever<Exclude<MiniAppsMethodParams<M>, undefined>>>;
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Any post-available event name which does not require arguments.
|
|
347
|
-
*/
|
|
348
|
-
export type MiniAppsEmptyMethodName = {
|
|
349
|
-
[M in MiniAppsMethodName]: undefined extends MiniAppsMethodParams<M> ? M : never;
|
|
350
|
-
}[MiniAppsMethodName];
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Any post-available event name which require arguments.
|
|
354
|
-
*/
|
|
355
|
-
export type MiniAppsNonEmptyMethodName = {
|
|
356
|
-
[M in MiniAppsMethodName]: MiniAppsMethodAcceptParams<M> extends true ? M : never;
|
|
357
|
-
}[MiniAppsMethodName];
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Method names which have versioned params.
|
|
361
|
-
*/
|
|
362
|
-
export type MiniAppsMethodWithVersionedParams = {
|
|
363
|
-
[M in MiniAppsMethodName]: IsNever<MiniAppsMethods[M]['versionedParams']> extends true ? never : M;
|
|
364
|
-
}[MiniAppsMethodName];
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Method parameters which appear only in the specific Telegram Mini Apps version.
|
|
368
|
-
*/
|
|
369
|
-
export type MiniAppsMethodVersionedParams<M extends MiniAppsMethodWithVersionedParams> =
|
|
370
|
-
MiniAppsMethods[M]['versionedParams'];
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Describes the native popup.
|
|
3
|
-
*/
|
|
4
|
-
export interface PopupParams {
|
|
5
|
-
/**
|
|
6
|
-
* The text to be displayed in the popup title, 0-64 characters.
|
|
7
|
-
*/
|
|
8
|
-
title: string;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The message to be displayed in the body of the popup, 1-256 characters.
|
|
12
|
-
*/
|
|
13
|
-
message: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* List of buttons to be displayed in the popup, 1-3 buttons.
|
|
17
|
-
*/
|
|
18
|
-
buttons: PopupButton[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Describes the native popup button.
|
|
23
|
-
* @see https://docs.telegram-mini-apps.com/platform/apps-communication/methods#popupbutton
|
|
24
|
-
*/
|
|
25
|
-
export type PopupButton = {
|
|
26
|
-
/**
|
|
27
|
-
* Identifier of the button, 0-64 characters.
|
|
28
|
-
*/
|
|
29
|
-
id: string;
|
|
30
|
-
} & ({
|
|
31
|
-
/**
|
|
32
|
-
* Type of the button:
|
|
33
|
-
* - `default`, a button with the default style;
|
|
34
|
-
* - `destructive`, a button with a style that indicates a destructive
|
|
35
|
-
* action (e.g. "Remove", "Delete", etc.).
|
|
36
|
-
*
|
|
37
|
-
* @default "default"
|
|
38
|
-
*/
|
|
39
|
-
type?: 'default' | 'destructive';
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The text to be displayed on the button, 0-64 characters.
|
|
43
|
-
*/
|
|
44
|
-
text: string;
|
|
45
|
-
} | {
|
|
46
|
-
/**
|
|
47
|
-
* Type of the button:
|
|
48
|
-
* - `ok`, a button with the localized text "OK";
|
|
49
|
-
* - `close`, a button with the localized text "Close";
|
|
50
|
-
* - `cancel`, a button with the localized text "Cancel".
|
|
51
|
-
*/
|
|
52
|
-
type: 'ok' | 'close' | 'cancel';
|
|
53
|
-
});
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
MiniAppsEmptyMethodName,
|
|
3
|
-
MiniAppsMethodName,
|
|
4
|
-
MiniAppsMethodParams,
|
|
5
|
-
MiniAppsNonEmptyMethodName,
|
|
6
|
-
} from './methods.js';
|
|
7
|
-
import { logger, targetOrigin as globalTargetOrigin } from '../../globals.js';
|
|
8
|
-
import {
|
|
9
|
-
hasExternalNotify,
|
|
10
|
-
hasWebviewProxy,
|
|
11
|
-
isIframe,
|
|
12
|
-
} from '../env/index.js';
|
|
13
|
-
|
|
14
|
-
interface PostEventOptions {
|
|
15
|
-
/**
|
|
16
|
-
* Origin used while posting message. This option is only used in case,
|
|
17
|
-
* current environment is browser (Web version of Telegram) and could
|
|
18
|
-
* be used for test purposes.
|
|
19
|
-
* @default 'https://web.telegram.org'
|
|
20
|
-
*/
|
|
21
|
-
targetOrigin?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type PostEvent = typeof postEvent;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Sends event to native application which launched Mini App. This function
|
|
28
|
-
* accepts only events, which require arguments.
|
|
29
|
-
* @param eventType - event name.
|
|
30
|
-
* @param params - event parameters.
|
|
31
|
-
* @param options - posting options.
|
|
32
|
-
* @throws {Error} Bridge could not determine current environment and possible way to send event.
|
|
33
|
-
*/
|
|
34
|
-
export function postEvent<E extends MiniAppsNonEmptyMethodName>(
|
|
35
|
-
eventType: E,
|
|
36
|
-
params: MiniAppsMethodParams<E>,
|
|
37
|
-
options?: PostEventOptions,
|
|
38
|
-
): void;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Sends event to native application which launched Mini App. This function
|
|
42
|
-
* accepts only events, which require arguments.
|
|
43
|
-
* @param eventType - event name.
|
|
44
|
-
* @param options - posting options.
|
|
45
|
-
* @throws {Error} Bridge could not determine current environment and possible way to send event.
|
|
46
|
-
*/
|
|
47
|
-
export function postEvent(eventType: MiniAppsEmptyMethodName, options?: PostEventOptions): void;
|
|
48
|
-
|
|
49
|
-
export function postEvent(
|
|
50
|
-
eventType: MiniAppsMethodName,
|
|
51
|
-
paramsOrOptions?: MiniAppsMethodParams<MiniAppsMethodName> | PostEventOptions,
|
|
52
|
-
options?: PostEventOptions,
|
|
53
|
-
): void {
|
|
54
|
-
let postOptions: PostEventOptions = {};
|
|
55
|
-
let eventData: any;
|
|
56
|
-
|
|
57
|
-
if (paramsOrOptions === undefined && options === undefined) {
|
|
58
|
-
// Parameters and options were not passed.
|
|
59
|
-
postOptions = {};
|
|
60
|
-
} else if (paramsOrOptions !== undefined && options !== undefined) {
|
|
61
|
-
// Both parameters and options passed.
|
|
62
|
-
postOptions = options;
|
|
63
|
-
eventData = paramsOrOptions;
|
|
64
|
-
} else if (paramsOrOptions !== undefined) {
|
|
65
|
-
// Only parameters were passed.
|
|
66
|
-
if ('targetOrigin' in paramsOrOptions) {
|
|
67
|
-
postOptions = paramsOrOptions;
|
|
68
|
-
} else {
|
|
69
|
-
eventData = paramsOrOptions;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const { targetOrigin = globalTargetOrigin() } = postOptions;
|
|
73
|
-
|
|
74
|
-
logger.log(`Calling method "${eventType}"`, eventData);
|
|
75
|
-
|
|
76
|
-
// Telegram Web.
|
|
77
|
-
if (isIframe()) {
|
|
78
|
-
window.parent.postMessage(JSON.stringify({
|
|
79
|
-
eventType,
|
|
80
|
-
eventData,
|
|
81
|
-
}), targetOrigin);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Telegram for Windows Phone or Android.
|
|
86
|
-
if (hasExternalNotify(window)) {
|
|
87
|
-
window.external.notify(JSON.stringify({ eventType, eventData }));
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Telegram for iOS and macOS.
|
|
92
|
-
if (hasWebviewProxy(window)) {
|
|
93
|
-
window.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Otherwise current environment is unknown, and we are not able to send event.
|
|
98
|
-
throw new Error(
|
|
99
|
-
'Unable to determine current environment and possible way to send event.',
|
|
100
|
-
);
|
|
101
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { json, string } from '~/parsing/index.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Message format used in communication between client and Telegram applications.
|
|
5
|
-
*/
|
|
6
|
-
export interface MiniAppsMessage {
|
|
7
|
-
/**
|
|
8
|
-
* Event name.
|
|
9
|
-
*/
|
|
10
|
-
eventType: string;
|
|
11
|
-
/**
|
|
12
|
-
* Event parameters.
|
|
13
|
-
*/
|
|
14
|
-
eventData?: unknown;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const parser = json<MiniAppsMessage>({
|
|
18
|
-
eventType: string(),
|
|
19
|
-
eventData: (value) => value,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Parses value as a message between client and Telegram applications.
|
|
24
|
-
* @param value - value to parse.
|
|
25
|
-
*/
|
|
26
|
-
export function parseMessage(value: unknown): MiniAppsMessage {
|
|
27
|
-
return parser.parse(value);
|
|
28
|
-
}
|