@types/telegram-web-app 1.0.0 → 6.2.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.
- telegram-web-app/README.md +2 -2
- telegram-web-app/index.d.ts +269 -8
- telegram-web-app/package.json +8 -3
telegram-web-app/README.md
CHANGED
|
@@ -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:
|
|
11
|
+
* Last updated: Fri, 02 Sep 2022 10:02:40 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).
|
telegram-web-app/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Type definitions for non-npm package telegram-web-app
|
|
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;
|
|
@@ -24,6 +24,10 @@ interface WebApp {
|
|
|
24
24
|
* the bot's server and only after it has been validated.
|
|
25
25
|
*/
|
|
26
26
|
initDataUnsafe: WebAppInitData;
|
|
27
|
+
/**
|
|
28
|
+
* The version of the Bot API available in the user's Telegram app.
|
|
29
|
+
*/
|
|
30
|
+
version: string;
|
|
27
31
|
/**
|
|
28
32
|
* The color scheme currently used in the Telegram app. Either “light” or
|
|
29
33
|
* “dark”. Also available as the CSS variable var(--tg-color-scheme).
|
|
@@ -75,19 +79,72 @@ interface WebApp {
|
|
|
75
79
|
*/
|
|
76
80
|
viewportStableHeight: number;
|
|
77
81
|
/**
|
|
78
|
-
*
|
|
79
|
-
|
|
82
|
+
* Current header color in the #RRGGBB format.
|
|
83
|
+
*/
|
|
84
|
+
headerColor: string;
|
|
85
|
+
/**
|
|
86
|
+
* Current background color in the #RRGGBB format.
|
|
87
|
+
*/
|
|
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;
|
|
94
|
+
/**
|
|
95
|
+
* An object for controlling the back button which can be displayed in the
|
|
96
|
+
* header of the Web App in the Telegram interface.
|
|
97
|
+
*/
|
|
98
|
+
BackButton: BackButton;
|
|
99
|
+
/**
|
|
100
|
+
* An object for controlling the main button, which is displayed at the
|
|
101
|
+
* bottom of the Web App in the Telegram interface.
|
|
80
102
|
*/
|
|
81
103
|
MainButton: MainButton;
|
|
104
|
+
/**
|
|
105
|
+
* An object for controlling haptic feedback.
|
|
106
|
+
*/
|
|
107
|
+
HapticFeedback: HapticFeedback;
|
|
108
|
+
/**
|
|
109
|
+
* Returns true if the user's app supports a version of the Bot API that is
|
|
110
|
+
* equal to or higher than the version passed as the parameter.
|
|
111
|
+
*/
|
|
112
|
+
isVersionAtLeast(version: string): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* A method that sets the app header color. You can only pass
|
|
115
|
+
* Telegram.WebApp.themeParams.bg_color or
|
|
116
|
+
* Telegram.WebApp.themeParams.secondary_bg_colo as a color or you can use
|
|
117
|
+
* keywords bg_color, secondary_bg_color instead.
|
|
118
|
+
*/
|
|
119
|
+
setHeaderColor(color: 'bg_color' | 'secondary_bg_color'): void;
|
|
120
|
+
/**
|
|
121
|
+
* A method that sets the app background color in the #RRGGBB format or you
|
|
122
|
+
* can use keywords bg_color, secondary_bg_color instead.
|
|
123
|
+
*/
|
|
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;
|
|
82
133
|
/**
|
|
83
134
|
* A method that sets the app event handler. Check the list of available
|
|
84
135
|
* events.
|
|
85
136
|
*/
|
|
86
|
-
onEvent(
|
|
87
|
-
|
|
137
|
+
onEvent(
|
|
138
|
+
eventType: 'themeChanged' | 'mainButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked' | 'popupClosed',
|
|
139
|
+
eventHandler: () => void,
|
|
140
|
+
): void;
|
|
141
|
+
onEvent(eventType: 'viewportChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
|
|
88
142
|
/** A method that deletes a previously set event handler. */
|
|
89
|
-
offEvent(
|
|
90
|
-
|
|
143
|
+
offEvent(
|
|
144
|
+
eventType: 'themeChanged' | 'mainButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked' | 'popupClosed',
|
|
145
|
+
eventHandler: () => void,
|
|
146
|
+
): void;
|
|
147
|
+
offEvent(eventType: 'viewportChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
|
|
91
148
|
/**
|
|
92
149
|
* A method used to send data to the bot. When this method is called, a
|
|
93
150
|
* service message is sent to the bot containing the data data of the length
|
|
@@ -97,6 +154,44 @@ interface WebApp {
|
|
|
97
154
|
* This method is only available for Web Apps launched via a Keyboard button.
|
|
98
155
|
*/
|
|
99
156
|
sendData(data: string): void;
|
|
157
|
+
/**
|
|
158
|
+
* A method that opens a link in an external browser. The Web App will not
|
|
159
|
+
* be closed. Note that this method can be called only in response to the
|
|
160
|
+
* user interaction with the Web App interface (e.g. click inside the Web
|
|
161
|
+
* App or on the main button)
|
|
162
|
+
*/
|
|
163
|
+
openLink(url: string): void;
|
|
164
|
+
/**
|
|
165
|
+
* A method that opens a telegram link inside Telegram app. The Web App will
|
|
166
|
+
* be closed.
|
|
167
|
+
*/
|
|
168
|
+
openTelegramLink(url: string): void;
|
|
169
|
+
/**
|
|
170
|
+
* A method that opens an invoice using the link url. The Web App will
|
|
171
|
+
* receive the event invoiceClosed when the invoice is closed. If an
|
|
172
|
+
* optional callback parameter was passed, the callback function will be
|
|
173
|
+
* called and the invoice status will be passed as the first argument.
|
|
174
|
+
*/
|
|
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;
|
|
100
195
|
/**
|
|
101
196
|
* A method that informs the Telegram app that the Web App is ready to be
|
|
102
197
|
* displayed. It is recommended to call this method as early as possible, as
|
|
@@ -152,6 +247,93 @@ interface ThemeParams {
|
|
|
152
247
|
* var(--tg-theme-button-text-color).
|
|
153
248
|
*/
|
|
154
249
|
button_text_color: string;
|
|
250
|
+
/**
|
|
251
|
+
* Optional. Bot API 6.1+ Secondary background color in the #RRGGBB format.
|
|
252
|
+
* Also available as the CSS variable var(--tg-theme-secondary-bg-color).
|
|
253
|
+
*/
|
|
254
|
+
secondary_bg_color: string;
|
|
255
|
+
}
|
|
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
|
+
|
|
310
|
+
/**
|
|
311
|
+
* This object controls the back button, which can be displayed in the header of
|
|
312
|
+
* the Web App in the Telegram interface.
|
|
313
|
+
*/
|
|
314
|
+
interface BackButton {
|
|
315
|
+
/**
|
|
316
|
+
* Shows whether the button is visible. Set to false by default.
|
|
317
|
+
*/
|
|
318
|
+
isVisible: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* A method that sets the button press event handler. An alias for
|
|
321
|
+
* Telegram.WebApp.onEvent('backButtonClicked', callback)
|
|
322
|
+
*/
|
|
323
|
+
onClick(callback: () => void): BackButton;
|
|
324
|
+
/**
|
|
325
|
+
* A method that removes the button press event handler. An alias for
|
|
326
|
+
* Telegram.WebApp.offEvent('backButtonClicked', callback)
|
|
327
|
+
*/
|
|
328
|
+
offClick(callback: () => void): BackButton;
|
|
329
|
+
/**
|
|
330
|
+
* A method to make the button active and visible.
|
|
331
|
+
*/
|
|
332
|
+
show(): void;
|
|
333
|
+
/**
|
|
334
|
+
* A method to hide the button.
|
|
335
|
+
*/
|
|
336
|
+
hide(): void;
|
|
155
337
|
}
|
|
156
338
|
|
|
157
339
|
/**
|
|
@@ -228,6 +410,41 @@ interface MainButtonParams {
|
|
|
228
410
|
is_visible?: boolean;
|
|
229
411
|
}
|
|
230
412
|
|
|
413
|
+
/**
|
|
414
|
+
* This object controls haptic feedback.
|
|
415
|
+
*/
|
|
416
|
+
interface HapticFeedback {
|
|
417
|
+
/**
|
|
418
|
+
* A method tells that an impact occurred. The Telegram app may play the
|
|
419
|
+
* appropriate haptics based on style value passed. Style can be one of
|
|
420
|
+
* these values:
|
|
421
|
+
* - light, indicates a collision between small or lightweight UI objects,
|
|
422
|
+
* - medium, indicates a collision between medium-sized or medium-weight UI
|
|
423
|
+
* objects,
|
|
424
|
+
* - heavy, indicates a collision between large or heavyweight UI objects,
|
|
425
|
+
* - rigid, indicates a collision between hard or inflexible UI objects,
|
|
426
|
+
* - soft, indicates a collision between soft or flexible UI objects.
|
|
427
|
+
*/
|
|
428
|
+
impactOccurred(style: 'light' | 'medium' | 'heavy' | 'rigid' | 'soft'): () => void;
|
|
429
|
+
/**
|
|
430
|
+
* A method tells that a task or action has succeeded, failed, or produced a
|
|
431
|
+
* warning. The Telegram app may play the appropriate haptics based on type
|
|
432
|
+
* value passed. Type can be one of these values:
|
|
433
|
+
* - error, indicates that a task or action has failed,
|
|
434
|
+
* - success, indicates that a task or action has completed successfully,
|
|
435
|
+
* - warning, indicates that a task or action produced a warning.
|
|
436
|
+
*/
|
|
437
|
+
notificationOccurred(type: 'error' | 'success' | 'warning'): () => void;
|
|
438
|
+
/**
|
|
439
|
+
* A method tells that the user has changed a selection. The Telegram app
|
|
440
|
+
* may play the appropriate haptics.
|
|
441
|
+
*
|
|
442
|
+
* Do not use this feedback when the user makes or confirms a selection; use
|
|
443
|
+
* it only when the selection changes.
|
|
444
|
+
*/
|
|
445
|
+
selectionChanged(): void;
|
|
446
|
+
}
|
|
447
|
+
|
|
231
448
|
/**
|
|
232
449
|
* This object contains data that is transferred to the Web App when it is
|
|
233
450
|
* opened. It is empty if the Web App was launched from a keyboard button.
|
|
@@ -246,6 +463,12 @@ interface WebAppInitData {
|
|
|
246
463
|
* Web Apps launched via the attachment menu.
|
|
247
464
|
*/
|
|
248
465
|
receiver?: WebAppUser;
|
|
466
|
+
/**
|
|
467
|
+
* An object containing data about the chat where the bot was launched via
|
|
468
|
+
* the attachment menu. Returned for supergroups, channels and group chats –
|
|
469
|
+
* only for Web Apps launched via the attachment menu.
|
|
470
|
+
*/
|
|
471
|
+
chat?: WebAppChat;
|
|
249
472
|
/**
|
|
250
473
|
* The value of the startattach parameter, passed via link. Only returned for
|
|
251
474
|
* Web Apps when launched from the attachment menu via link. The value of the
|
|
@@ -254,6 +477,11 @@ interface WebAppInitData {
|
|
|
254
477
|
* away.
|
|
255
478
|
*/
|
|
256
479
|
start_param?: string;
|
|
480
|
+
/**
|
|
481
|
+
* Time in seconds, after which a message can be sent via the
|
|
482
|
+
* answerWebAppQuery method.
|
|
483
|
+
*/
|
|
484
|
+
can_send_after?: number;
|
|
257
485
|
/** Unix time when the form was opened. */
|
|
258
486
|
auth_date: number;
|
|
259
487
|
/**
|
|
@@ -283,9 +511,42 @@ interface WebAppUser {
|
|
|
283
511
|
username?: string;
|
|
284
512
|
/** IETF language tag of the user's language. Returns in user field only. */
|
|
285
513
|
language_code?: string;
|
|
514
|
+
/** True, if this user is a Telegram Premium user. */
|
|
515
|
+
is_premium?: true;
|
|
286
516
|
/**
|
|
287
517
|
* URL of the user’s profile photo. The photo can be in .jpeg or .svg formats.
|
|
288
518
|
* Only returned for Web Apps launched from the attachment menu.
|
|
289
519
|
*/
|
|
290
520
|
photo_url?: string;
|
|
291
521
|
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* This object represents a chat.
|
|
525
|
+
*/
|
|
526
|
+
interface WebAppChat {
|
|
527
|
+
/**
|
|
528
|
+
* Unique identifier for this chat. This number may have more than 32
|
|
529
|
+
* significant bits and some programming languages may have
|
|
530
|
+
* difficulty/silent defects in interpreting it. But it has at most 52
|
|
531
|
+
* significant bits, so a signed 64-bit integer or double-precision float
|
|
532
|
+
* type are safe for storing this identifier.
|
|
533
|
+
*/
|
|
534
|
+
id: number;
|
|
535
|
+
/**
|
|
536
|
+
* Type of chat, can be either “group”, “supergroup” or “channel”
|
|
537
|
+
*/
|
|
538
|
+
type: 'group' | 'supergroup' | 'channel';
|
|
539
|
+
/**
|
|
540
|
+
* Title of the chat
|
|
541
|
+
*/
|
|
542
|
+
title: string;
|
|
543
|
+
/**
|
|
544
|
+
* Username of the chat
|
|
545
|
+
*/
|
|
546
|
+
username?: string;
|
|
547
|
+
/**
|
|
548
|
+
* URL of the chat’s photo. The photo can be in .jpeg or .svg formats. Only
|
|
549
|
+
* returned for Web Apps launched from the attachment menu.
|
|
550
|
+
*/
|
|
551
|
+
photo_url?: string;
|
|
552
|
+
}
|
telegram-web-app/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/telegram-web-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.2.1",
|
|
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": "
|
|
24
|
-
"typeScriptVersion": "
|
|
28
|
+
"typesPublisherContentHash": "8de5d205746171b3f8012f70c1006dc3f6a9b848a056d449623b1ec0315600fa",
|
|
29
|
+
"typeScriptVersion": "4.1"
|
|
25
30
|
}
|