@tma.js/bridge 2.3.3 → 4.0.0-rc.0

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