@tma.js/bridge 1.3.9 → 1.3.11

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.
@@ -7,209 +7,313 @@ import type { RequestId } from '../shared.js';
7
7
  import type { AnyInvokeCustomMethodParams } from './invoke-custom-method.js';
8
8
 
9
9
  /**
10
- * Color key which could be used tot update header color.
10
+ * Color key which could be used to update header color.
11
11
  */
12
12
  export type HeaderColorKey = 'bg_color' | 'secondary_bg_color';
13
13
 
14
+ /**
15
+ * Chat type which could be used when calling `web_app_switch_inline_query` method.
16
+ */
17
+ export type SwitchInlineQueryChatType = 'users' | 'bots' | 'groups' | 'channels';
18
+
14
19
  type CreateParams<P = never, SupportCheckKey extends UnionKeys<P> = never> = {
15
20
  params: P;
16
21
  supportCheckKey: SupportCheckKey;
17
22
  };
18
23
 
19
24
  /**
20
- * Describes list of events and their parameters that could be posted by
21
- * Bridge.
22
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods
25
+ * Describes list of events and their parameters that could be posted by Bridge.
26
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods
23
27
  */
24
28
  export interface MethodsParams {
25
29
  /**
26
- * Notifies parent iframe about current frame is ready.
27
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#iframe_ready
28
- * @since 6.0
30
+ * Notifies parent iframe about the current frame is ready. This method is only used in the Web
31
+ * version of Telegram. As a result, Mini App will receive `set_custom_style` event.
32
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#iframe-ready
29
33
  */
30
34
  iframe_ready: CreateParams;
31
35
 
32
36
  /**
33
- * Closes WebApp.
34
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_close
35
- * @since 6.0
37
+ * Closes Mini App.
38
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-close
36
39
  */
37
40
  web_app_close: CreateParams;
38
41
 
39
42
  /**
40
- * Closes QR scanner.
41
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_close_scan_qr_popup
42
- * @since 6.4
43
+ * Closes a QR scanner. The Telegram application creates `scan_qr_popup_closed` event.
44
+ * @since v6.4
45
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-close-scan-qr-popup
43
46
  */
44
47
  web_app_close_scan_qr_popup: CreateParams;
45
48
 
46
49
  /**
47
- * Sends data to bot.
48
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_data_send
49
- * @since 6.0
50
+ * Sends data to the bot. When this method is called, a service message is sent to the bot
51
+ * containing the data of the length up to 4096 bytes. Then, Mini App will be closed.
52
+ *
53
+ * To get more information, take a look at `web_app_data` field in the
54
+ * class [Message](https://core.telegram.org/bots/api#message).
55
+ *
56
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-data-send
50
57
  */
51
- web_app_data_send: CreateParams<{ data: string }>;
58
+ web_app_data_send: CreateParams<{
59
+ /**
60
+ * Data to send to a bot. Should not have size of more than 4096 bytes.
61
+ */
62
+ data: string;
63
+ }>;
52
64
 
53
65
  /**
54
- * Expands Web App.
55
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_expand
56
- * @since 6.0
66
+ * Expands the Mini App.
67
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-expand
57
68
  */
58
69
  web_app_expand: CreateParams;
59
70
 
71
+ // TODO: 'getRequestedContact'. https://telegram.org/js/telegram-web-app.js
60
72
  /**
61
73
  * Invokes custom method.
62
- * @since 6.9
74
+ * @since v6.9
75
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-invoke-custom-method
63
76
  */
64
77
  web_app_invoke_custom_method: CreateParams<AnyInvokeCustomMethodParams>;
65
78
 
66
79
  /**
67
- * Opens new invoice.
68
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_open_invoice
69
- * @since 6.1
80
+ * Opens an invoice by its specified slug. More information about invoices in
81
+ * this [documentation](https://core.telegram.org/bots/payments).
82
+ * @since v6.1
83
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-open-invoice
70
84
  */
71
- web_app_open_invoice: CreateParams<{ slug: string }>;
85
+ web_app_open_invoice: CreateParams<{
86
+ /**
87
+ * Invoice unique identifier.
88
+ */
89
+ slug: string;
90
+ }>;
72
91
 
73
92
  /**
74
- * Opens link in default browser. Doesn't close application.
75
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_open_link
76
- * @since 6.0
93
+ * Opens link in the default browser. Mini App will not be closed.
94
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-open-link
77
95
  */
78
96
  web_app_open_link: CreateParams<{
79
- url: string,
97
+ /**
98
+ * URL to be opened by Telegram application. Should be a full path with `https` protocol.
99
+ */
100
+ url: string;
80
101
 
81
- // TODO: Add to docs.
82
102
  /**
83
103
  * Link will be opened in Instant View mode if possible.
104
+ * @since v6.4
84
105
  * @see https://instantview.telegram.org/
85
- * @since 6.4
86
106
  */
87
107
  try_instant_view?: boolean;
88
108
  }, 'try_instant_view'>;
89
109
 
90
110
  /**
91
- * Opens new popup.
92
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_open_popup
93
- * @since 6.2
111
+ * Opens a new popup. When user closes the popup, Telegram creates the `popup_closed` event.
112
+ * @since v6.2
113
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-open-popup
94
114
  */
95
115
  web_app_open_popup: CreateParams<PopupParams>;
96
116
 
97
117
  /**
98
- * Opens QR scanner.
99
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_open_scan_qr_popup
100
- * @since 6.4
118
+ * Opens a QR scanner. When the scanner was closed, the Telegram application creates
119
+ * the `scan_qr_popup_closed` event. When the scanner reads QR, Telegram creates the
120
+ * `qr_text_received` event.
121
+ * @since v6.4
122
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-open-scan-qr-popup
101
123
  */
102
- web_app_open_scan_qr_popup: CreateParams<{ text?: string }>;
124
+ web_app_open_scan_qr_popup: CreateParams<{
125
+ /**
126
+ * Text to be displayed in the QR scanner.
127
+ */
128
+ text?: string;
129
+ }>;
103
130
 
104
131
  /**
105
- * Opens link which has format like "https://t.me/*".
106
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_open_tg_link
107
- * @since 6.1
132
+ * Opens the Telegram link by its pathname and query parameters. The link will be opened in the
133
+ * Telegram app, Mini App will be closed.
134
+ * @since v6.1
135
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-open-tg-link
108
136
  */
109
- web_app_open_tg_link: CreateParams<{ path_full: string }>;
137
+ web_app_open_tg_link: CreateParams<{
138
+ /**
139
+ * Should be a value taken from the link of this format: `https://t.me/{path_full}`. Can
140
+ * additionally contain query parameters.
141
+ */
142
+ path_full: string;
143
+ }>;
110
144
 
111
145
  /**
112
- * Reads text from clipboard.
113
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_read_text_from_clipboard
114
- * @since 6.4
146
+ * Reads text from the clipboard. The method accepts a request identifier which is used to
147
+ * appropriately retrieve the method execution result from the `clipboard_text_received` event.
148
+ * @since v6.4
149
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-read-text-from-clipboard
115
150
  */
116
- web_app_read_text_from_clipboard: CreateParams<{ req_id: RequestId }>;
151
+ web_app_read_text_from_clipboard: CreateParams<{
152
+ /**
153
+ * Unique request identifier. Should be any unique string to handle the generated event
154
+ * appropriately.
155
+ */
156
+ req_id: RequestId;
157
+ }>;
117
158
 
118
159
  /**
119
- * Notifies Telegram about current application is ready to be shown.
120
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_ready
121
- * @since 6.0
160
+ * Notifies Telegram about current application is ready to be shown. This method will make
161
+ * Telegram to remove application loader and display Mini App.
162
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-ready
122
163
  */
123
164
  web_app_ready: CreateParams;
124
165
 
166
+ // TODO: Check if it is right. It probably requests other user phone.
125
167
  /**
126
168
  * Requests access to current user's phone.
127
- * @since 6.9
169
+ * @since v6.9
170
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-request-phone
128
171
  */
129
172
  web_app_request_phone: CreateParams;
130
173
 
131
174
  /**
132
- * Requests current theme from Telegram.
133
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_request_theme
134
- * @since 6.0
175
+ * Requests current theme from Telegram. As a result, Telegram will create `theme_changed` event.
176
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-request-theme
135
177
  */
136
178
  web_app_request_theme: CreateParams;
137
179
 
138
180
  /**
139
- * Requests current viewport information from Telegram.
140
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_request_viewport
141
- * @since 6.0
181
+ * Requests current viewport information from Telegram. As a result, Telegram will create
182
+ * `viewport_changed` event.
183
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-request-viewport
142
184
  */
143
185
  web_app_request_viewport: CreateParams;
144
186
 
145
187
  /**
146
188
  * Requests write message access to current user.
147
- * @since 6.9
189
+ * @since v6.9
190
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-rqeuest-write-access
148
191
  */
149
192
  web_app_request_write_access: CreateParams;
150
193
 
151
194
  /**
152
- * Updates current background color.
153
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_set_background_color
154
- * @since 6.1
195
+ * Updates the Mini App background color.
196
+ * @since v6.1
197
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-set-background-color
155
198
  */
156
- web_app_set_background_color: CreateParams<{ color: string }>;
199
+ web_app_set_background_color: CreateParams<{
200
+ /**
201
+ * The Mini App background color in `#RRGGBB` format.
202
+ */
203
+ color: RGB;
204
+ }>;
157
205
 
158
206
  /**
159
- * Updates current header color.
160
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_set_header_color
161
- * @since 6.1
207
+ * Updates the Mini App header color.
208
+ * @since v6.1
209
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-set-header-color
162
210
  */
163
211
  web_app_set_header_color: CreateParams<
164
- | { color_key: HeaderColorKey }
165
212
  | {
166
213
  /**
167
- * @since 6.9
214
+ * The Mini App header color key.
168
215
  */
169
- color: RGB
216
+ color_key: HeaderColorKey
217
+ }
218
+ | {
219
+ /**
220
+ * Color in RGB format.
221
+ * @since v6.9
222
+ */
223
+ color: RGB;
170
224
  }, 'color'>;
171
225
 
172
226
  /**
173
- * Updates current information about back button.
174
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_setup_back_button
175
- * @since 6.1
227
+ * Updates the Back Button settings.
228
+ * @since v6.1
229
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-setup-back-button
176
230
  */
177
- web_app_setup_back_button: CreateParams<{ is_visible: boolean }>;
231
+ web_app_setup_back_button: CreateParams<{
232
+ /**
233
+ * Should the Back Button be visible.
234
+ */
235
+ is_visible: boolean;
236
+ }>;
178
237
 
179
238
  /**
180
- * Changes current closing confirmation requirement status.
181
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_setup_closing_behavior
182
- * @since 6.0
239
+ * Updates current closing behavior.
240
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-setup-closing-behavior
183
241
  */
184
- web_app_setup_closing_behavior: CreateParams<{ need_confirmation: boolean }>;
242
+ web_app_setup_closing_behavior: CreateParams<{
243
+ /**
244
+ * Will user be prompted in case, an application is going to be closed.
245
+ */
246
+ need_confirmation: boolean;
247
+ }>;
185
248
 
186
249
  /**
187
- * Updates current information about main button.
188
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_setup_main_button
189
- * @since 6.0
250
+ * Updates the Main Button settings.
251
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-setup-main-button
190
252
  */
191
253
  web_app_setup_main_button: CreateParams<{
254
+ /**
255
+ * Should the Main Button be displayed.
256
+ */
192
257
  is_visible?: boolean;
258
+ /**
259
+ * Should the Main Button be enabled.
260
+ */
193
261
  is_active?: boolean;
262
+ /**
263
+ * Should loader inside the Main Button be displayed. Use this property in case, some
264
+ * operation takes time. This loader will make user notified about it.
265
+ */
194
266
  is_progress_visible?: boolean;
267
+ /**
268
+ * Text inside the Main Button.
269
+ */
195
270
  text?: string;
271
+ /**
272
+ * The Main Button background color in `#RRGGBB` format.
273
+ */
196
274
  color?: string;
275
+ /**
276
+ * The Main Button text color in `#RRGGBB` format.
277
+ */
197
278
  text_color?: string;
198
279
  }>;
199
280
 
200
281
  /**
201
- * Updates current information about Settings Button.
202
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_setup_settings_button
203
- * @since 6.10
282
+ * Updates current state of Settings Button.
283
+ * @since v6.10
284
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-setup-settings-button
204
285
  */
205
286
  web_app_setup_settings_button: CreateParams<{
287
+ /**
288
+ * Should the Settings Button be displayed.
289
+ */
206
290
  is_visible: boolean;
207
291
  }>;
208
292
 
293
+ /**
294
+ * Inserts the bot's username and the specified inline query in the current chat's input field.
295
+ * Query may be empty, in which case only the bot's username will be inserted. The client prompts
296
+ * the user to choose a specific chat, then opens that chat and inserts the bot's username and
297
+ * the specified inline query in the input field.
298
+ * @since v6.7
299
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-switch-inline-query
300
+ */
301
+ web_app_switch_inline_query: CreateParams<{
302
+ /**
303
+ * Text which should be inserted in the input after the current bot name. Max length is
304
+ * 256 symbols.
305
+ */
306
+ query: string;
307
+ /**
308
+ * List of chat types which could be chosen to send the message. Could be empty list.
309
+ */
310
+ chat_types: SwitchInlineQueryChatType[];
311
+ }>;
312
+
209
313
  /**
210
314
  * Generates haptic feedback event.
211
- * @see https://docs.telegram-mini-apps.com/docs/apps-communication/methods#web_app_trigger_haptic_feedback
212
- * @since 6.1
315
+ * @since v6.1
316
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#web-app-trigger-haptic-feedback
213
317
  */
214
318
  web_app_trigger_haptic_feedback: CreateParams<AnyHapticFeedbackParams>;
215
319
  }
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Describes the native popup.
3
- * @see https://core.telegram.org/bots/webapps#popupparams
4
3
  */
5
4
  export interface PopupParams {
6
5
  /**
@@ -21,35 +20,34 @@ export interface PopupParams {
21
20
 
22
21
  /**
23
22
  * Describes the native popup button.
24
- * @see https://core.telegram.org/bots/webapps#popupbutton
23
+ * @see https://docs.telegram-mini-apps.com/apps-communication/methods#popupbutton
25
24
  */
26
25
  export type PopupButton = {
27
26
  /**
28
27
  * Identifier of the button, 0-64 characters.
29
28
  */
30
29
  id: string;
31
- } & (
32
- {
33
- /**
34
- * Type of the button:
35
- * - `default`, a button with the default style;
36
- * - `destructive`, a button with a style that indicates a destructive
37
- * action (e.g. "Remove", "Delete", etc.).
38
- *
39
- * @default "default"
40
- */
41
- type?: 'default' | 'destructive';
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';
42
40
 
43
- /**
44
- * The text to be displayed on the button, 0-64 characters.
45
- */
46
- text: string;
47
- } | {
41
+ /**
42
+ * The text to be displayed on the button, 0-64 characters.
43
+ */
44
+ text: string;
45
+ } | {
48
46
  /**
49
47
  * Type of the button:
50
48
  * - `ok`, a button with the localized text "OK";
51
49
  * - `close`, a button with the localized text "Close";
52
50
  * - `cancel`, a button with the localized text "Cancel".
53
51
  */
54
- type: 'ok' | 'close' | 'cancel';
55
- });
52
+ type: 'ok' | 'close' | 'cancel';
53
+ });
@@ -25,7 +25,7 @@ interface PostEventOptions {
25
25
  export type PostEvent = typeof postEvent;
26
26
 
27
27
  /**
28
- * Sends event to native application which launched Web App. This function
28
+ * Sends event to native application which launched Mini App. This function
29
29
  * accepts only events, which require arguments.
30
30
  * @param eventType - event name.
31
31
  * @param params - event parameters.
@@ -40,7 +40,7 @@ export function postEvent<E extends NonEmptyMethodName>(
40
40
  ): void;
41
41
 
42
42
  /**
43
- * Sends event to native application which launched Web App. This function
43
+ * Sends event to native application which launched Mini App. This function
44
44
  * accepts only events, which require arguments.
45
45
  * @param eventType - event name.
46
46
  * @param options - posting options.
package/src/supports.ts CHANGED
@@ -89,6 +89,8 @@ export function supports(
89
89
  case 'web_app_open_scan_qr_popup':
90
90
  case 'web_app_read_text_from_clipboard':
91
91
  return lessOrEqual('6.4', paramOrVersion);
92
+ case 'web_app_switch_inline_query':
93
+ return lessOrEqual('6.7', paramOrVersion);
92
94
  case 'web_app_invoke_custom_method':
93
95
  case 'web_app_request_write_access':
94
96
  case 'web_app_request_phone':