@tma.js/bridge 1.4.1 → 2.0.1

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.
Files changed (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +44 -13
  3. package/dist/dts/applyPolyfills.d.ts +5 -0
  4. package/dist/dts/base64-url.d.ts +24 -0
  5. package/dist/dts/env/hasWebviewProxy.d.ts +10 -0
  6. package/dist/dts/env/isIframe.d.ts +5 -0
  7. package/dist/dts/env/isTMA.d.ts +31 -0
  8. package/dist/dts/env/mockTelegramEnv.d.ts +57 -0
  9. package/dist/dts/errors.d.ts +27 -0
  10. package/dist/dts/events/createEmitter.d.ts +58 -0
  11. package/dist/dts/events/emitEvent.d.ts +33 -0
  12. package/dist/dts/events/emitter.d.ts +2 -11
  13. package/dist/dts/events/types/events.d.ts +721 -0
  14. package/dist/dts/events/types/index.d.ts +3 -0
  15. package/dist/dts/events/types/listening.d.ts +5 -0
  16. package/dist/dts/events/types/misc.d.ts +16 -0
  17. package/dist/dts/globals.d.ts +45 -14
  18. package/dist/dts/index.d.ts +24 -7
  19. package/dist/dts/launch-params.d.ts +32 -0
  20. package/dist/dts/methods/captureSameReq.d.ts +10 -0
  21. package/dist/dts/methods/createPostEvent.d.ts +27 -7
  22. package/dist/dts/methods/postEvent.d.ts +31 -25
  23. package/dist/dts/methods/postMessage.d.ts +7 -0
  24. package/dist/dts/methods/supports.d.ts +15 -0
  25. package/dist/dts/methods/types/custom-method.d.ts +59 -0
  26. package/dist/dts/methods/types/index.d.ts +6 -0
  27. package/dist/dts/methods/types/methods.d.ts +756 -0
  28. package/dist/dts/methods/types/misc.d.ts +27 -0
  29. package/dist/dts/methods/{popup.d.ts → types/popup.d.ts} +1 -1
  30. package/dist/dts/methods/types/utils.d.ts +9 -0
  31. package/dist/dts/obj-prop-helpers.d.ts +39 -0
  32. package/dist/dts/start-param.d.ts +53 -0
  33. package/dist/dts/utils/compareVersions.d.ts +10 -0
  34. package/dist/dts/utils/invokeCustomMethod.d.ts +34 -0
  35. package/dist/dts/utils/request.d.ts +90 -0
  36. package/dist/index.cjs +3 -1
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.iife.js +3 -1
  39. package/dist/index.iife.js.map +1 -1
  40. package/dist/index.js +977 -0
  41. package/dist/index.js.map +1 -0
  42. package/package.json +26 -26
  43. package/dist/dts/env.d.ts +0 -29
  44. package/dist/dts/errors/MethodUnsupportedError.d.ts +0 -8
  45. package/dist/dts/errors/ParameterUnsupportedError.d.ts +0 -8
  46. package/dist/dts/errors/index.d.ts +0 -2
  47. package/dist/dts/events/events.d.ts +0 -130
  48. package/dist/dts/events/index.d.ts +0 -7
  49. package/dist/dts/events/off.d.ts +0 -7
  50. package/dist/dts/events/on.d.ts +0 -10
  51. package/dist/dts/events/onTelegramEvent.d.ts +0 -7
  52. package/dist/dts/events/once.d.ts +0 -9
  53. package/dist/dts/events/parsers/clipboardTextReceived.d.ts +0 -13
  54. package/dist/dts/events/parsers/customMethodInvoked.d.ts +0 -16
  55. package/dist/dts/events/parsers/index.d.ts +0 -9
  56. package/dist/dts/events/parsers/invoiceClosed.d.ts +0 -12
  57. package/dist/dts/events/parsers/phoneRequested.d.ts +0 -8
  58. package/dist/dts/events/parsers/popupClosed.d.ts +0 -8
  59. package/dist/dts/events/parsers/qrTextReceived.d.ts +0 -7
  60. package/dist/dts/events/parsers/theme-changed.d.ts +0 -42
  61. package/dist/dts/events/parsers/viewportChanged.d.ts +0 -19
  62. package/dist/dts/events/parsers/writeAccessRequested.d.ts +0 -8
  63. package/dist/dts/events/subscribe.d.ts +0 -9
  64. package/dist/dts/events/unsubscribe.d.ts +0 -6
  65. package/dist/dts/methods/index.d.ts +0 -6
  66. package/dist/dts/methods/invoke-custom-method.d.ts +0 -24
  67. package/dist/dts/methods/methods.d.ts +0 -330
  68. package/dist/dts/request.d.ts +0 -66
  69. package/dist/dts/shared.d.ts +0 -5
  70. package/dist/dts/supports.d.ts +0 -15
  71. package/dist/index.mjs +0 -317
  72. package/dist/index.mjs.map +0 -1
  73. package/src/env.ts +0 -49
  74. package/src/errors/MethodUnsupportedError.ts +0 -13
  75. package/src/errors/ParameterUnsupportedError.ts +0 -13
  76. package/src/errors/index.ts +0 -2
  77. package/src/events/emitter.ts +0 -126
  78. package/src/events/events.ts +0 -169
  79. package/src/events/index.ts +0 -7
  80. package/src/events/off.ts +0 -12
  81. package/src/events/on.ts +0 -17
  82. package/src/events/onTelegramEvent.ts +0 -83
  83. package/src/events/once.ts +0 -16
  84. package/src/events/parsers/clipboardTextReceived.ts +0 -27
  85. package/src/events/parsers/customMethodInvoked.ts +0 -26
  86. package/src/events/parsers/index.ts +0 -9
  87. package/src/events/parsers/invoiceClosed.ts +0 -26
  88. package/src/events/parsers/phoneRequested.ts +0 -14
  89. package/src/events/parsers/popupClosed.ts +0 -19
  90. package/src/events/parsers/qrTextReceived.ts +0 -14
  91. package/src/events/parsers/theme-changed.ts +0 -58
  92. package/src/events/parsers/viewportChanged.ts +0 -33
  93. package/src/events/parsers/writeAccessRequested.ts +0 -14
  94. package/src/events/subscribe.ts +0 -16
  95. package/src/events/unsubscribe.ts +0 -11
  96. package/src/globals.ts +0 -38
  97. package/src/index.ts +0 -7
  98. package/src/methods/createPostEvent.ts +0 -39
  99. package/src/methods/haptic.ts +0 -52
  100. package/src/methods/index.ts +0 -6
  101. package/src/methods/invoke-custom-method.ts +0 -25
  102. package/src/methods/methods.ts +0 -373
  103. package/src/methods/popup.ts +0 -53
  104. package/src/methods/postEvent.ts +0 -101
  105. package/src/request.ts +0 -168
  106. package/src/shared.ts +0 -5
  107. package/src/supports.ts +0 -82
  108. /package/dist/dts/methods/{haptic.d.ts → types/haptic-feedback.d.ts} +0 -0
@@ -0,0 +1,756 @@
1
+ import { If, IsNever } from '@tma.js/toolkit';
2
+ import { RGB } from '@tma.js/types';
3
+ import { AnyInvokeCustomMethodParams } from './custom-method.js';
4
+ import { AnyHapticFeedbackParams } from './haptic-feedback.js';
5
+ import { BackgroundColor, BottomBarColor, HeaderColorKey, OpenLinkBrowser, SecondaryButtonPosition, SwitchInlineQueryChatType } from './misc.js';
6
+ import { PopupParams } from './popup.js';
7
+ import { CreateMethodParams } from './utils.js';
8
+ type WithReqId<T = {}> = T & {
9
+ /**
10
+ * Unique request identifier. Should be any unique string to handle the generated event
11
+ * appropriately.
12
+ */
13
+ req_id: string;
14
+ };
15
+ interface ButtonParams {
16
+ /**
17
+ * Should the button shine.
18
+ * @since 7.10
19
+ */
20
+ has_shine_effect?: boolean;
21
+ /**
22
+ * Should the button be displayed.
23
+ */
24
+ is_visible?: boolean;
25
+ /**
26
+ * Should the button be enabled.
27
+ */
28
+ is_active?: boolean;
29
+ /**
30
+ * Should loader inside the button be displayed. Use this property in case, some
31
+ * operation takes time. This loader will make user notified about it.
32
+ */
33
+ is_progress_visible?: boolean;
34
+ /**
35
+ * Text inside the button.
36
+ */
37
+ text?: string;
38
+ /**
39
+ * The button background color in `#RRGGBB` format.
40
+ */
41
+ color?: RGB;
42
+ /**
43
+ * The Main Button text color in `#RRGGBB` format.
44
+ */
45
+ text_color?: RGB;
46
+ }
47
+ /**
48
+ * Describes a list of events and their parameters that could be posted.
49
+ * @see https://docs.telegram-mini-apps.com/platform/methods
50
+ */
51
+ export interface Methods {
52
+ /**
53
+ * Notifies parent iframe about the current frame is ready. This method is only used in the Web
54
+ * version of Telegram. As a result, Mini App will receive `set_custom_style` event.
55
+ * @see https://docs.telegram-mini-apps.com/platform/methods#iframe-ready
56
+ */
57
+ iframe_ready: CreateMethodParams<{
58
+ /**
59
+ * True, if the current Mini App supports native reloading.
60
+ */
61
+ reload_supported?: boolean;
62
+ } | undefined>;
63
+ /**
64
+ * Notifies parent iframe about the current iframe is going to reload.
65
+ * @see https://docs.telegram-mini-apps.com/platform/methods#iframe-will-reload
66
+ */
67
+ iframe_will_reload: CreateMethodParams;
68
+ /**
69
+ * Prompts the user to add the Mini App to the home screen. Note that if the device cannot
70
+ * determine the installation status, the event may not be received even if the icon has
71
+ * been added.
72
+ * @since v8.0
73
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-add-to-home-screen
74
+ */
75
+ web_app_add_to_home_screen: CreateMethodParams;
76
+ /**
77
+ * Emitted by bot mini apps to ask the client to initialize the biometric authentication manager
78
+ * object for the current bot, emitting a `biometry_info_received` event on completion.
79
+ *
80
+ * This request should just initialize the client-side state, i.e. by checking if biometric
81
+ * authentication is even available or not, it should not ask the user anything.
82
+ * @since v7.2
83
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-biometry-get-info
84
+ */
85
+ web_app_biometry_get_info: CreateMethodParams;
86
+ /**
87
+ * Opens the biometric access settings for bots. Useful when you need to request biometrics
88
+ * access to users who haven't granted it yet.
89
+ *
90
+ * _Note that this method can be called only in response to user interaction with the Mini
91
+ * App interface (e.g. a click inside the Mini App or on the main button)_.
92
+ * @since v7.2
93
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-biometry-open-settings
94
+ */
95
+ web_app_biometry_open_settings: CreateMethodParams;
96
+ /**
97
+ * Emitted by bot mini apps to ask the user permission to use biometric authentication,
98
+ * emitting a `biometry_info_received` event on completion.
99
+ *
100
+ * This request should not actually prompt biometric authentication, it should just ask the
101
+ * user permission to use them, and a popup should be shown only if the user hasn't already
102
+ * allowed or denied the usage of biometric authentication for the bot associated with the
103
+ * mini app.
104
+ * @since v7.2
105
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-biometry-request-access
106
+ */
107
+ web_app_biometry_request_access: CreateMethodParams<{
108
+ /**
109
+ * Reason to request biometry access. Should be at least 1 symbol length, but not
110
+ * more than 128 symbols.
111
+ */
112
+ reason?: string;
113
+ }>;
114
+ /**
115
+ * Attempts to authenticate a user using biometrics and fetch a previously stored
116
+ * secure token, emitting the `biometry_auth_requested` event on completion, containing either
117
+ * an error, or a decrypted biometric token (or an empty string if no token was configured yet).
118
+ *
119
+ * Should only be used if the `token_saved` field of the `biometry_info_received` event object
120
+ * is equal to true.
121
+ *
122
+ * If a user has previously disallowed the bot from using biometric authentication, this
123
+ * request will immediately fail, emitting an appropriate `biometry_auth_requested` event.
124
+ * @since v7.2
125
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-biometry-request-auth
126
+ */
127
+ web_app_biometry_request_auth: CreateMethodParams<{
128
+ /**
129
+ * Reason to request biometry data. Should be at least 1 symbol length, but not more than
130
+ * 128 symbols.
131
+ */
132
+ reason?: string;
133
+ }>;
134
+ /**
135
+ * Attempts to authenticate using biometrics and store the biometric token
136
+ * securely on a device, emitting a `biometry_token_updated` event on completion.
137
+ *
138
+ * This token will be safely stored by the Telegram client and will be associated with the bot
139
+ * that owns the mini app.
140
+ *
141
+ * If the user has previously disallowed the bot from using biometric authentication, this
142
+ * request will immediately fail, emitting an appropriate biometry_token_updated event.
143
+ * @since v7.2
144
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-biometry-update-token
145
+ */
146
+ web_app_biometry_update_token: CreateMethodParams<{
147
+ /**
148
+ * Optional string field, containing the reason why the bot is asking to authenticate using
149
+ * biometrics (1-128 chars, used in the prompt).
150
+ */
151
+ reason?: string;
152
+ /**
153
+ * The new token (string, 0-1024 chars), or an empty string to remove it.
154
+ */
155
+ token: string;
156
+ }>;
157
+ /**
158
+ * Sends a request to the native Telegram application to check if the current mini
159
+ * application is added to the device's home screen.
160
+ * @since v8.0
161
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-check-home-screen
162
+ */
163
+ web_app_check_home_screen: CreateMethodParams;
164
+ /**
165
+ * Requests location-related functionality availability state.
166
+ * @since v8.0
167
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-check-location
168
+ */
169
+ web_app_check_location: CreateMethodParams;
170
+ /**
171
+ * Closes Mini App.
172
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-close
173
+ */
174
+ web_app_close: CreateMethodParams<{
175
+ /**
176
+ * Should the client return to the previous activity.
177
+ * @since v7.6
178
+ */
179
+ return_back?: boolean;
180
+ } | undefined, 'return_back'>;
181
+ /**
182
+ * Closes a QR scanner. The Telegram application creates `scan_qr_popup_closed` event.
183
+ * @since v6.4
184
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-close-scan-qr-popup
185
+ */
186
+ web_app_close_scan_qr_popup: CreateMethodParams;
187
+ /**
188
+ * Sends data to the bot. When this method is called, a service message is sent to the bot
189
+ * containing the data of the length up to 4096 bytes. Then, Mini App will be closed.
190
+ *
191
+ * To get more information, take a look at `web_app_data` field in the
192
+ * class [Message](https://core.telegram.org/bots/api#message).
193
+ *
194
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-data-send
195
+ */
196
+ web_app_data_send: CreateMethodParams<{
197
+ /**
198
+ * Data to send to a bot. Should not have size of more than 4096 bytes.
199
+ */
200
+ data: string;
201
+ }>;
202
+ /**
203
+ * Clears all keys previously stored by the bot in the device's local storage.
204
+ * @since 9.0
205
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-device-storage-clear
206
+ */
207
+ web_app_device_storage_clear: CreateMethodParams<WithReqId>;
208
+ /**
209
+ * Receives a value from the device's local storage using the specified key.
210
+ * @since 9.0
211
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-device-storage-get-key
212
+ */
213
+ web_app_device_storage_get_key: CreateMethodParams<WithReqId<{
214
+ /**
215
+ * A key name to retrieve.
216
+ */
217
+ key: string;
218
+ }>>;
219
+ /**
220
+ * Stores a value in the device's local storage using the specified key.
221
+ * @since 9.0
222
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-device-storage-save-key
223
+ */
224
+ web_app_device_storage_save_key: CreateMethodParams<WithReqId<{
225
+ /**
226
+ * A key to use to store the value.
227
+ */
228
+ key: string;
229
+ /**
230
+ * A value to store for the specified key. Passing `null` will lead to the key removal.
231
+ */
232
+ value: string | null;
233
+ }>>;
234
+ /**
235
+ * Exits fullscreen mode for miniapp.
236
+ * @since v8.0
237
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-exit-fullscreen
238
+ */
239
+ web_app_exit_fullscreen: CreateMethodParams;
240
+ /**
241
+ * Expands the Mini App.
242
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-expand
243
+ */
244
+ web_app_expand: CreateMethodParams;
245
+ /**
246
+ * Hides the on-screen keyboard, if it is currently visible. Does nothing if the keyboard is
247
+ * not active.
248
+ * @since v9.1
249
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-hide-keyboard
250
+ */
251
+ web_app_hide_keyboard: CreateMethodParams;
252
+ /**
253
+ * Invokes custom method.
254
+ * @since v6.9
255
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-invoke-custom-method
256
+ */
257
+ web_app_invoke_custom_method: CreateMethodParams<AnyInvokeCustomMethodParams>;
258
+ /**
259
+ * Opens an invoice by its specified slug. More information about invoices in
260
+ * this [documentation](https://core.telegram.org/bots/payments).
261
+ * @since v6.1
262
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-open-invoice
263
+ */
264
+ web_app_open_invoice: CreateMethodParams<{
265
+ /**
266
+ * Invoice unique identifier.
267
+ */
268
+ slug: string;
269
+ }>;
270
+ /**
271
+ * Opens a link in a default browser. The Mini App will not be closed.
272
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-open-link
273
+ */
274
+ web_app_open_link: CreateMethodParams<{
275
+ /**
276
+ * URL to be opened by Telegram application. Should be a full path with `https` protocol.
277
+ */
278
+ url: string;
279
+ /**
280
+ * Link will be opened in Instant View mode if possible.
281
+ * @since v6.4
282
+ * @see https://instantview.telegram.org/
283
+ */
284
+ try_instant_view?: boolean;
285
+ /**
286
+ * A preferred browser to open the link in.
287
+ * @since v7.6
288
+ */
289
+ try_browser?: OpenLinkBrowser;
290
+ }, 'try_instant_view' | 'try_browser'>;
291
+ /**
292
+ * Opens the location access settings for bots. Useful when you need to request location access
293
+ * from users who haven't granted it yet.
294
+ *
295
+ * Note that this method can be called only in response to user interaction with the Mini App
296
+ * interface (e.g., a click inside the Mini App or on the main button).
297
+ * @since v8.0
298
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-open-location-settings
299
+ */
300
+ web_app_open_location_settings: CreateMethodParams;
301
+ /**
302
+ * Opens a new popup. When a user closes the popup, Telegram creates the `popup_closed` event.
303
+ * @since v6.2
304
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-open-popup
305
+ */
306
+ web_app_open_popup: CreateMethodParams<PopupParams>;
307
+ /**
308
+ * Opens a QR scanner. When the scanner was closed, the Telegram application creates
309
+ * the `scan_qr_popup_closed` event. When the scanner reads QR, Telegram creates the
310
+ * `qr_text_received` event.
311
+ * @since v6.4
312
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-open-scan-qr-popup
313
+ */
314
+ web_app_open_scan_qr_popup: CreateMethodParams<{
315
+ /**
316
+ * Text to be displayed in the QR scanner.
317
+ */
318
+ text?: string;
319
+ }>;
320
+ /**
321
+ * Opens the Telegram link by its pathname and query parameters. The link will be opened in the
322
+ * Telegram app, Mini App will be closed.
323
+ * @since v6.1
324
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-open-tg-link
325
+ */
326
+ web_app_open_tg_link: CreateMethodParams<{
327
+ /**
328
+ * Should be a value taken from the link of this format: `https://t.me/{path_full}`. Can
329
+ * additionally contain query parameters.
330
+ */
331
+ path_full: string;
332
+ }>;
333
+ /**
334
+ * Reads text from the clipboard. The method accepts a request identifier which is used to
335
+ * appropriately retrieve the method execution result from the `clipboard_text_received` event.
336
+ * @since v6.4
337
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-read-text-from-clipboard
338
+ */
339
+ web_app_read_text_from_clipboard: CreateMethodParams<WithReqId>;
340
+ /**
341
+ * Notifies Telegram about current application is ready to be shown. This method will make
342
+ * Telegram to remove application loader and display Mini App.
343
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-ready
344
+ */
345
+ web_app_ready: CreateMethodParams;
346
+ /**
347
+ * Requests content safe area of the user's phone.
348
+ * @since v8.0
349
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-content-safe-area
350
+ */
351
+ web_app_request_content_safe_area: CreateMethodParams;
352
+ /**
353
+ * Shows a native popup requesting permission for the bot to manage user's emoji status.
354
+ * @since v8.0
355
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-emoji-status-access
356
+ */
357
+ web_app_request_emoji_status_access: CreateMethodParams;
358
+ /**
359
+ * Displays a native popup prompting the user to download a file.
360
+ * @since v8.0
361
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-file-download
362
+ */
363
+ web_app_request_file_download: CreateMethodParams<{
364
+ /**
365
+ * The HTTPS URL of the file to be downloaded.
366
+ */
367
+ url: string;
368
+ /**
369
+ * The suggested name for the downloaded file.
370
+ */
371
+ file_name: string;
372
+ }>;
373
+ /**
374
+ * Requests to open the mini app in fullscreen.
375
+ * @since v8.0
376
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-fullscreen
377
+ */
378
+ web_app_request_fullscreen: CreateMethodParams;
379
+ /**
380
+ * Requests location data.
381
+ * @since v8.0
382
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-location
383
+ */
384
+ web_app_request_location: CreateMethodParams;
385
+ /**
386
+ * Requests access to current user's phone.
387
+ * @since v6.9
388
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-phone
389
+ */
390
+ web_app_request_phone: CreateMethodParams;
391
+ /**
392
+ * Requests safe area of the user's phone.
393
+ * @since v8.0
394
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-safe-area
395
+ */
396
+ web_app_request_safe_area: CreateMethodParams;
397
+ /**
398
+ * Requests current theme from Telegram. As a result, Telegram will create `theme_changed` event.
399
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-theme
400
+ */
401
+ web_app_request_theme: CreateMethodParams;
402
+ /**
403
+ * Requests current viewport information from Telegram. As a result, Telegram will create
404
+ * `viewport_changed` event.
405
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-request-viewport
406
+ */
407
+ web_app_request_viewport: CreateMethodParams;
408
+ /**
409
+ * Requests write message access to the current user.
410
+ * @since v6.9
411
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-rqeuest-write-access
412
+ */
413
+ web_app_request_write_access: CreateMethodParams;
414
+ /**
415
+ * Clears all keys previously stored by the bot in the device's secure storage.
416
+ * @since 9.0
417
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-secure-storage-clear
418
+ */
419
+ web_app_secure_storage_clear: CreateMethodParams<WithReqId>;
420
+ /**
421
+ * Receives a value from the device's secure storage using the specified key.
422
+ * @since 9.0
423
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-secure-storage-get-key
424
+ */
425
+ web_app_secure_storage_get_key: CreateMethodParams<WithReqId<{
426
+ /**
427
+ * A key to use to store the value.
428
+ */
429
+ key: string;
430
+ }>>;
431
+ /**
432
+ * Attempts to restore a key that previously existed on the current device. When called, the user
433
+ * will be asked for permission to restore the value.
434
+ * @since 9.0
435
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-secure-storage-restore-key
436
+ */
437
+ web_app_secure_storage_restore_key: CreateMethodParams<WithReqId<{
438
+ /**
439
+ * A key to use to restore the value.
440
+ */
441
+ key: string;
442
+ }>>;
443
+ /**
444
+ * Stores a value in the device's secure storage using the specified key.
445
+ * @since 9.0
446
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-secure-storage-save-key
447
+ */
448
+ web_app_secure_storage_save_key: CreateMethodParams<WithReqId<{
449
+ /**
450
+ * A key to use to store the value.
451
+ */
452
+ key: string;
453
+ /**
454
+ * A value to store for the specified key. Passing `null` will lead to the key removal.
455
+ */
456
+ value: string | null;
457
+ }>>;
458
+ /**
459
+ * Opens a dialog allowing the user to share a message provided by the bot.
460
+ * @since v8.0
461
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-send-prepared-message
462
+ */
463
+ web_app_send_prepared_message: CreateMethodParams<{
464
+ /**
465
+ * Identifier of the message
466
+ * ([PreparedInlineMessage](https://core.telegram.org/bots/api#preparedinlinemessage))
467
+ * previously obtained via the Bot API method
468
+ * [savePreparedInlineMessage](https://core.telegram.org/bots/api#savepreparedinlinemessage).
469
+ */
470
+ id: string;
471
+ }>;
472
+ /**
473
+ * Updates the Mini App background color.
474
+ * @since v6.1
475
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-set-background-color
476
+ */
477
+ web_app_set_background_color: CreateMethodParams<{
478
+ /**
479
+ * Color to set.
480
+ */
481
+ color: BackgroundColor;
482
+ }>;
483
+ /**
484
+ * Updates the mini app bottom bar background color.
485
+ * @since v7.10
486
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-set-bottom-bar-color
487
+ */
488
+ web_app_set_bottom_bar_color: CreateMethodParams<{
489
+ /**
490
+ * Color to set.
491
+ */
492
+ color: BottomBarColor;
493
+ }>;
494
+ /**
495
+ * Opens a dialog allowing the user to set the specified custom emoji as their status.
496
+ * @since v8.0
497
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-set-emoji-status
498
+ */
499
+ web_app_set_emoji_status: CreateMethodParams<{
500
+ /**
501
+ * Custom emoji identifier to set.
502
+ */
503
+ custom_emoji_id: string;
504
+ /**
505
+ * The status expiration time in seconds.
506
+ */
507
+ duration?: number;
508
+ }>;
509
+ /**
510
+ * Updates the Mini App header color.
511
+ * @since v6.1
512
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-set-header-color
513
+ */
514
+ web_app_set_header_color: CreateMethodParams<{
515
+ /**
516
+ * The Mini App header color key.
517
+ */
518
+ color_key: HeaderColorKey;
519
+ } | {
520
+ /**
521
+ * Color in RGB format.
522
+ * @since v6.9
523
+ */
524
+ color: RGB;
525
+ }, 'color'>;
526
+ /**
527
+ * Updates the Back Button settings.
528
+ * @since v6.1
529
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-setup-back-button
530
+ */
531
+ web_app_setup_back_button: CreateMethodParams<{
532
+ /**
533
+ * Should the Back Button be visible.
534
+ */
535
+ is_visible: boolean;
536
+ }>;
537
+ /**
538
+ * Updates current closing behavior.
539
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-setup-closing-behavior
540
+ */
541
+ web_app_setup_closing_behavior: CreateMethodParams<{
542
+ /**
543
+ * Will user be prompted in case, an application is going to be closed.
544
+ */
545
+ need_confirmation: boolean;
546
+ }>;
547
+ /**
548
+ * Updates the Main Button settings.
549
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-setup-main-button
550
+ */
551
+ web_app_setup_main_button: CreateMethodParams<ButtonParams, 'has_shine_effect'>;
552
+ /**
553
+ * Updates the secondary button settings.
554
+ * @since v7.10
555
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-setup-secondary-button
556
+ */
557
+ web_app_setup_secondary_button: CreateMethodParams<ButtonParams & {
558
+ /**
559
+ * Position of the secondary button. It applies only if both the main and secondary buttons
560
+ * are visible.
561
+ *
562
+ * Supported values:
563
+ * - `left`, displayed to the left of the main button.
564
+ * - `right`, displayed to the right of the main button.
565
+ * - `top`, displayed above the main button.
566
+ * - `bottom`, displayed below the main button.
567
+ */
568
+ position?: SecondaryButtonPosition;
569
+ }>;
570
+ /**
571
+ * Updates the current state of the Settings Button.
572
+ * @since v6.10
573
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-setup-settings-button
574
+ */
575
+ web_app_setup_settings_button: CreateMethodParams<{
576
+ /**
577
+ * Should the Settings Button be displayed.
578
+ */
579
+ is_visible: boolean;
580
+ }>;
581
+ /**
582
+ * Changes swipe behavior.
583
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-setup-swipe-behavior
584
+ * @since v7.7
585
+ */
586
+ web_app_setup_swipe_behavior: CreateMethodParams<{
587
+ allow_vertical_swipe: boolean;
588
+ }>;
589
+ /**
590
+ * A method that opens the native story editor.
591
+ * @since v7.8
592
+ */
593
+ web_app_share_to_story: CreateMethodParams<{
594
+ /**
595
+ * A media URL which will be used as a background for a created story.
596
+ */
597
+ media_url: string;
598
+ /**
599
+ * The caption to be added to the media.
600
+ * 0-200 characters for regular users and 0-2048 characters for premium subscribers.
601
+ * @see https://telegram.org/faq_premium#telegram-premium
602
+ */
603
+ text?: string;
604
+ /**
605
+ * An object that describes a widget link to be included in the story.
606
+ * Note that only premium subscribers can post stories with links.
607
+ * @see https://telegram.org/faq_premium#telegram-premium
608
+ */
609
+ widget_link?: {
610
+ /**
611
+ * The URL to be included in the story.
612
+ */
613
+ url: string;
614
+ /**
615
+ * The name to be displayed for the widget link, 0-48 characters.
616
+ */
617
+ name?: string;
618
+ };
619
+ }>;
620
+ /**
621
+ * Starts tracking accelerometer data.
622
+ * @since v8.0
623
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-start-accelerometer
624
+ */
625
+ web_app_start_accelerometer: CreateMethodParams<{
626
+ /**
627
+ * The refresh rate in milliseconds, with acceptable values ranging from 20 to 1000.
628
+ * Note that refresh_rate may not be supported on all platforms, so the actual tracking
629
+ * frequency may differ from the specified value.
630
+ */
631
+ refresh_rate: number;
632
+ }>;
633
+ /**
634
+ * Starts tracking device orientation data.
635
+ * @since v8.0
636
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-start-device-orientation
637
+ */
638
+ web_app_start_device_orientation: CreateMethodParams<{
639
+ /**
640
+ * The refresh rate in milliseconds, with acceptable values ranging from 20 to 1000.
641
+ * Note that refresh_rate may not be supported on all platforms, so the actual tracking
642
+ * frequency may differ from the specified value.
643
+ */
644
+ refresh_rate: number;
645
+ /**
646
+ * Pass true to receive absolute orientation data, allowing you to determine the device's
647
+ * attitude relative to magnetic north. Use this option if implementing features like a
648
+ * compass in your app. If relative data is sufficient, pass false.
649
+ *
650
+ * Keep in mind that some devices may not support absolute orientation data. In such cases,
651
+ * you will receive relative data even if need_absolute=true is passed.
652
+ */
653
+ need_absolute?: boolean;
654
+ }>;
655
+ /**
656
+ * Starts tracking gyroscope data.
657
+ * @since v8.0
658
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-start-gyroscope
659
+ */
660
+ web_app_start_gyroscope: CreateMethodParams<{
661
+ /**
662
+ * The refresh rate in milliseconds, with acceptable values ranging from 20 to 1000.
663
+ * Note that refresh_rate may not be supported on all platforms, so the actual tracking
664
+ * frequency may differ from the specified value.
665
+ */
666
+ refresh_rate: number;
667
+ }>;
668
+ /**
669
+ * Stops tracking accelerometer data.
670
+ * @since v8.0
671
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-stop-accelerometer
672
+ */
673
+ web_app_stop_accelerometer: CreateMethodParams;
674
+ /**
675
+ * Stops tracking device orientation data.
676
+ * @since v8.0
677
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-stop-device-orientation
678
+ */
679
+ web_app_stop_device_orientation: CreateMethodParams;
680
+ /**
681
+ * Stops tracking gyroscope data.
682
+ * @since v8.0
683
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-stop-gyroscope
684
+ */
685
+ web_app_stop_gyroscope: CreateMethodParams;
686
+ /**
687
+ * Inserts the bot's username and the specified inline query in the current chat's input field.
688
+ * Query may be empty, in which case only the bot's username will be inserted. The client prompts
689
+ * the user to choose a specific chat, then opens that chat and inserts the bot's username and
690
+ * the specified inline query in the input field.
691
+ * @since v6.7
692
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-switch-inline-query
693
+ */
694
+ web_app_switch_inline_query: CreateMethodParams<{
695
+ /**
696
+ * Text which should be inserted in the input after the current bot name. Max length is
697
+ * 256 symbols.
698
+ */
699
+ query: string;
700
+ /**
701
+ * List of chat types which could be chosen to send the message. Could be empty list.
702
+ */
703
+ chat_types: SwitchInlineQueryChatType[];
704
+ }>;
705
+ /**
706
+ * Locks the Mini App’s orientation to its current mode (either portrait or landscape). Once
707
+ * locked, the orientation remains fixed, regardless of device rotation. This is useful if a
708
+ * stable orientation is needed during specific interactions.
709
+ * @since v8.0
710
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-toggle-orientation-lock
711
+ */
712
+ web_app_toggle_orientation_lock: CreateMethodParams<{
713
+ locked: boolean;
714
+ }>;
715
+ /**
716
+ * Generates haptic feedback event.
717
+ * @since v6.1
718
+ * @see https://docs.telegram-mini-apps.com/platform/methods#web-app-trigger-haptic-feedback
719
+ */
720
+ web_app_trigger_haptic_feedback: CreateMethodParams<AnyHapticFeedbackParams>;
721
+ }
722
+ /**
723
+ * Mini Apps method name.
724
+ */
725
+ export type MethodName = keyof Methods;
726
+ /**
727
+ * Parameters of the specified Mini Apps method.
728
+ */
729
+ export type MethodParams<M extends MethodName> = Methods[M]['params'];
730
+ /**
731
+ * Methods with optional parameters.
732
+ */
733
+ export type MethodNameWithOptionalParams = {
734
+ [M in MethodName]: undefined extends MethodParams<M> ? M : never;
735
+ }[MethodName];
736
+ /**
737
+ * Methods without parameters.
738
+ */
739
+ export type MethodNameWithoutParams = {
740
+ [M in MethodName]: If<IsNever<MethodParams<M>>, M, never>;
741
+ }[MethodName];
742
+ /**
743
+ * Methods with parameters.
744
+ */
745
+ export type MethodNameWithRequiredParams = Exclude<MethodName, MethodNameWithoutParams | MethodNameWithOptionalParams>;
746
+ /**
747
+ * Method names which have versioned params.
748
+ */
749
+ export type MethodNameWithVersionedParams = {
750
+ [M in MethodName]: If<IsNever<Methods[M]['versionedParams']>, never, M>;
751
+ }[MethodName];
752
+ /**
753
+ * Method parameters which appear only in the specific Telegram Mini Apps version.
754
+ */
755
+ export type MethodVersionedParams<M extends MethodNameWithVersionedParams> = Methods[M]['versionedParams'];
756
+ export {};