@types/telegram-web-app 1.0.1 → 6.2.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.
@@ -8,9 +8,9 @@ This package contains type definitions for telegram-web-app (https://telegram.or
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/telegram-web-app.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Thu, 30 Jun 2022 19:02:28 GMT
11
+ * Last updated: Thu, 25 Aug 2022 11:02:15 GMT
12
12
  * Dependencies: none
13
13
  * Global values: `Telegram`
14
14
 
15
15
  # Credits
16
- These definitions were written by [KnorpelSenf](https://github.com/KnorpelSenf).
16
+ These definitions were written by [KnorpelSenf](https://github.com/KnorpelSenf), and [MKRhere](https://github.com/MKRhere).
@@ -1,6 +1,6 @@
1
- // Type definitions for non-npm package telegram-web-app 1.0
1
+ // Type definitions for non-npm package telegram-web-app 6.2
2
2
  // Project: https://telegram.org/js/telegram-web-app.js
3
- // Definitions by: KnorpelSenf <https://github.com/KnorpelSenf>
3
+ // Definitions by: KnorpelSenf <https://github.com/KnorpelSenf>, MKRhere <https://github.com/MKRhere>
4
4
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
5
 
6
6
  declare var Telegram: Telegram;
@@ -86,6 +86,11 @@ interface WebApp {
86
86
  * Current background color in the #RRGGBB format.
87
87
  */
88
88
  backgroundColor: string;
89
+ /**
90
+ * True, if the confirmation dialog is enabled while the user is trying to close the Web App.
91
+ * False, if the confirmation dialog is disabled.
92
+ */
93
+ isClosingConfirmationEnabled: boolean;
89
94
  /**
90
95
  * An object for controlling the back button which can be displayed in the
91
96
  * header of the Web App in the Telegram interface.
@@ -117,18 +122,26 @@ interface WebApp {
117
122
  * can use keywords bg_color, secondary_bg_color instead.
118
123
  */
119
124
  setBackgroundColor(color: 'bg_color' | 'secondary_bg_color' | string): void;
125
+ /**
126
+ * A method that enables a confirmation dialog while the user is trying to close the Web App.
127
+ */
128
+ enableClosingConfirmation(): void;
129
+ /**
130
+ * A method that disables the confirmation dialog while the user is trying to close the Web App.
131
+ */
132
+ disableClosingConfirmation(): void;
120
133
  /**
121
134
  * A method that sets the app event handler. Check the list of available
122
135
  * events.
123
136
  */
124
137
  onEvent(
125
- eventType: 'themeChanged' | 'mainButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked',
138
+ eventType: 'themeChanged' | 'mainButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked' | 'popupClosed',
126
139
  eventHandler: () => void,
127
140
  ): void;
128
141
  onEvent(eventType: 'viewPortChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
129
142
  /** A method that deletes a previously set event handler. */
130
143
  offEvent(
131
- eventType: 'themeChanged' | 'mainButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked',
144
+ eventType: 'themeChanged' | 'mainButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked' | 'popupClosed',
132
145
  eventHandler: () => void,
133
146
  ): void;
134
147
  offEvent(eventType: 'viewPortChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
@@ -160,6 +173,25 @@ interface WebApp {
160
173
  * called and the invoice status will be passed as the first argument.
161
174
  */
162
175
  openInvoice(url: string, callback: () => void): void;
176
+ /**
177
+ * A method that shows a native popup described by the params argument of the type PopupParams.
178
+ * The Web App will receive the event popupClosed when the popup is closed. If an optional
179
+ * callback parameter was passed, the callback function will be called and the field id of the
180
+ * pressed button will be passed as the first argument.
181
+ */
182
+ showPopup(params: PopupParams, callback?: (button_id: string) => void): void;
183
+ /**
184
+ * A method that shows message in a simple alert with a 'Close' button. If an optional callback
185
+ * parameter was passed, the callback function will be called when the popup is closed.
186
+ */
187
+ showAlert(message: string, callback?: () => void): void;
188
+ /**
189
+ * A method that shows message in a simple confirmation window with 'OK' and 'Cancel' buttons.
190
+ * If an optional callback parameter was passed, the callback function will be called when the
191
+ * popup is closed and the first argument will be a boolean indicating whether the user
192
+ * pressed the 'OK' button.
193
+ */
194
+ showConfirm(message: string, callback?: (ok?: boolean) => void): void;
163
195
  /**
164
196
  * A method that informs the Telegram app that the Web App is ready to be
165
197
  * displayed. It is recommended to call this method as early as possible, as
@@ -222,6 +254,59 @@ interface ThemeParams {
222
254
  secondary_bg_color: string;
223
255
  }
224
256
 
257
+ /**
258
+ * This object describes the native popup.
259
+ */
260
+ interface PopupParams {
261
+ /**
262
+ * The text to be displayed in the popup title, 0-64 characters.
263
+ */
264
+ title?: string;
265
+ /**
266
+ * The message to be displayed in the body of the popup, 1-256 characters.
267
+ */
268
+ message: string;
269
+ /**
270
+ * List of buttons to be displayed in the popup, 1-3 buttons. Set to [{“type”:“close”}] by default.
271
+ */
272
+ buttons?: PopupButton[];
273
+ }
274
+
275
+ /**
276
+ * This object describes the native popup button.
277
+ */
278
+ type PopupButton = {
279
+ /**
280
+ * Identifier of the button, 0-64 characters. Set to empty string by default.
281
+ * If the button is pressed, its id is returned in the callback and the popupClosed event.
282
+ */
283
+ id?: string;
284
+ /**
285
+ * Type of the button. Set to default by default.
286
+ * Can be one of these values:
287
+ * - `default`, a button with the default style,
288
+ * - `ok`, a button with the localized text “OK”,
289
+ * - `close`, a button with the localized text “Close”,
290
+ * - `cancel`, a button with the localized text “Cancel”,
291
+ * - `destructive`, a button with a style that indicates a destructive action (e.g. “Remove”, “Delete”, etc.).
292
+ */
293
+ type?: 'default' | 'ok' | 'close' | 'cancel' | 'destructive';
294
+ /**
295
+ * The text to be displayed on the button, 0-64 characters.
296
+ * Required if type is default or destructive. Irrelevant for other types.
297
+ */
298
+ text?: string;
299
+ } & (
300
+ | {
301
+ type: 'default' | 'destructive';
302
+ text: string;
303
+ }
304
+ | {
305
+ type: 'ok' | 'close' | 'cancel';
306
+ text?: string;
307
+ }
308
+ );
309
+
225
310
  /**
226
311
  * This object controls the back button, which can be displayed in the header of
227
312
  * the Web App in the Telegram interface.
@@ -426,6 +511,8 @@ interface WebAppUser {
426
511
  username?: string;
427
512
  /** IETF language tag of the user's language. Returns in user field only. */
428
513
  language_code?: string;
514
+ /** True, if this user is a Telegram Premium user. */
515
+ is_premium?: true;
429
516
  /**
430
517
  * URL of the user’s profile photo. The photo can be in .jpeg or .svg formats.
431
518
  * Only returned for Web Apps launched from the attachment menu.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/telegram-web-app",
3
- "version": "1.0.1",
3
+ "version": "6.2.0",
4
4
  "description": "TypeScript definitions for telegram-web-app",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/telegram-web-app",
6
6
  "license": "MIT",
@@ -9,6 +9,11 @@
9
9
  "name": "KnorpelSenf",
10
10
  "url": "https://github.com/KnorpelSenf",
11
11
  "githubUsername": "KnorpelSenf"
12
+ },
13
+ {
14
+ "name": "MKRhere",
15
+ "url": "https://github.com/MKRhere",
16
+ "githubUsername": "MKRhere"
12
17
  }
13
18
  ],
14
19
  "main": "",
@@ -20,6 +25,6 @@
20
25
  },
21
26
  "scripts": {},
22
27
  "dependencies": {},
23
- "typesPublisherContentHash": "bac4c92463a29523d87e9f18893207ba7d91af4599ea2b407d6682c7f70d0e47",
28
+ "typesPublisherContentHash": "75ffafb8efd21814c38b9404c08c2ad8b7ed82834fdaa4c5d1f666b06968b5a1",
24
29
  "typeScriptVersion": "4.0"
25
30
  }