@types/telegram-web-app 1.0.0 → 1.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.
@@ -8,7 +8,7 @@ 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: Mon, 25 Apr 2022 13:31:36 GMT
11
+ * Last updated: Thu, 30 Jun 2022 19:02:28 GMT
12
12
  * Dependencies: none
13
13
  * Global values: `Telegram`
14
14
 
@@ -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,18 +79,58 @@ interface WebApp {
75
79
  */
76
80
  viewportStableHeight: number;
77
81
  /**
78
- * An object for controlling the main button, which is displayed at the bottom
79
- * of the Web App in the Telegram interface.
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
+ * An object for controlling the back button which can be displayed in the
91
+ * header of the Web App in the Telegram interface.
92
+ */
93
+ BackButton: BackButton;
94
+ /**
95
+ * An object for controlling the main button, which is displayed at the
96
+ * bottom of the Web App in the Telegram interface.
80
97
  */
81
98
  MainButton: MainButton;
99
+ /**
100
+ * An object for controlling haptic feedback.
101
+ */
102
+ HapticFeedback: HapticFeedback;
103
+ /**
104
+ * Returns true if the user's app supports a version of the Bot API that is
105
+ * equal to or higher than the version passed as the parameter.
106
+ */
107
+ isVersionAtLeast(version: string): boolean;
108
+ /**
109
+ * A method that sets the app header color. You can only pass
110
+ * Telegram.WebApp.themeParams.bg_color or
111
+ * Telegram.WebApp.themeParams.secondary_bg_colo as a color or you can use
112
+ * keywords bg_color, secondary_bg_color instead.
113
+ */
114
+ setHeaderColor(color: 'bg_color' | 'secondary_bg_color'): void;
115
+ /**
116
+ * A method that sets the app background color in the #RRGGBB format or you
117
+ * can use keywords bg_color, secondary_bg_color instead.
118
+ */
119
+ setBackgroundColor(color: 'bg_color' | 'secondary_bg_color' | string): void;
82
120
  /**
83
121
  * A method that sets the app event handler. Check the list of available
84
122
  * events.
85
123
  */
86
- onEvent(eventType: 'themeChanged' | 'mainButtonClicked', eventHandler: () => void): void;
124
+ onEvent(
125
+ eventType: 'themeChanged' | 'mainButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked',
126
+ eventHandler: () => void,
127
+ ): void;
87
128
  onEvent(eventType: 'viewPortChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
88
129
  /** A method that deletes a previously set event handler. */
89
- offEvent(eventType: 'themeChanged' | 'mainButtonClicked', eventHandler: () => void): void;
130
+ offEvent(
131
+ eventType: 'themeChanged' | 'mainButtonClicked' | 'backButtonClicked' | 'settingsButtonClicked',
132
+ eventHandler: () => void,
133
+ ): void;
90
134
  offEvent(eventType: 'viewPortChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
91
135
  /**
92
136
  * A method used to send data to the bot. When this method is called, a
@@ -97,6 +141,25 @@ interface WebApp {
97
141
  * This method is only available for Web Apps launched via a Keyboard button.
98
142
  */
99
143
  sendData(data: string): void;
144
+ /**
145
+ * A method that opens a link in an external browser. The Web App will not
146
+ * be closed. Note that this method can be called only in response to the
147
+ * user interaction with the Web App interface (e.g. click inside the Web
148
+ * App or on the main button)
149
+ */
150
+ openLink(url: string): void;
151
+ /**
152
+ * A method that opens a telegram link inside Telegram app. The Web App will
153
+ * be closed.
154
+ */
155
+ openTelegramLink(url: string): void;
156
+ /**
157
+ * A method that opens an invoice using the link url. The Web App will
158
+ * receive the event invoiceClosed when the invoice is closed. If an
159
+ * optional callback parameter was passed, the callback function will be
160
+ * called and the invoice status will be passed as the first argument.
161
+ */
162
+ openInvoice(url: string, callback: () => void): void;
100
163
  /**
101
164
  * A method that informs the Telegram app that the Web App is ready to be
102
165
  * displayed. It is recommended to call this method as early as possible, as
@@ -152,6 +215,40 @@ interface ThemeParams {
152
215
  * var(--tg-theme-button-text-color).
153
216
  */
154
217
  button_text_color: string;
218
+ /**
219
+ * Optional. Bot API 6.1+ Secondary background color in the #RRGGBB format.
220
+ * Also available as the CSS variable var(--tg-theme-secondary-bg-color).
221
+ */
222
+ secondary_bg_color: string;
223
+ }
224
+
225
+ /**
226
+ * This object controls the back button, which can be displayed in the header of
227
+ * the Web App in the Telegram interface.
228
+ */
229
+ interface BackButton {
230
+ /**
231
+ * Shows whether the button is visible. Set to false by default.
232
+ */
233
+ isVisible: boolean;
234
+ /**
235
+ * A method that sets the button press event handler. An alias for
236
+ * Telegram.WebApp.onEvent('backButtonClicked', callback)
237
+ */
238
+ onClick(callback: () => void): BackButton;
239
+ /**
240
+ * A method that removes the button press event handler. An alias for
241
+ * Telegram.WebApp.offEvent('backButtonClicked', callback)
242
+ */
243
+ offClick(callback: () => void): BackButton;
244
+ /**
245
+ * A method to make the button active and visible.
246
+ */
247
+ show(): void;
248
+ /**
249
+ * A method to hide the button.
250
+ */
251
+ hide(): void;
155
252
  }
156
253
 
157
254
  /**
@@ -228,6 +325,41 @@ interface MainButtonParams {
228
325
  is_visible?: boolean;
229
326
  }
230
327
 
328
+ /**
329
+ * This object controls haptic feedback.
330
+ */
331
+ interface HapticFeedback {
332
+ /**
333
+ * A method tells that an impact occurred. The Telegram app may play the
334
+ * appropriate haptics based on style value passed. Style can be one of
335
+ * these values:
336
+ * - light, indicates a collision between small or lightweight UI objects,
337
+ * - medium, indicates a collision between medium-sized or medium-weight UI
338
+ * objects,
339
+ * - heavy, indicates a collision between large or heavyweight UI objects,
340
+ * - rigid, indicates a collision between hard or inflexible UI objects,
341
+ * - soft, indicates a collision between soft or flexible UI objects.
342
+ */
343
+ impactOccurred(style: 'light' | 'medium' | 'heavy' | 'rigid' | 'soft'): () => void;
344
+ /**
345
+ * A method tells that a task or action has succeeded, failed, or produced a
346
+ * warning. The Telegram app may play the appropriate haptics based on type
347
+ * value passed. Type can be one of these values:
348
+ * - error, indicates that a task or action has failed,
349
+ * - success, indicates that a task or action has completed successfully,
350
+ * - warning, indicates that a task or action produced a warning.
351
+ */
352
+ notificationOccurred(type: 'error' | 'success' | 'warning'): () => void;
353
+ /**
354
+ * A method tells that the user has changed a selection. The Telegram app
355
+ * may play the appropriate haptics.
356
+ *
357
+ * Do not use this feedback when the user makes or confirms a selection; use
358
+ * it only when the selection changes.
359
+ */
360
+ selectionChanged(): void;
361
+ }
362
+
231
363
  /**
232
364
  * This object contains data that is transferred to the Web App when it is
233
365
  * opened. It is empty if the Web App was launched from a keyboard button.
@@ -246,6 +378,12 @@ interface WebAppInitData {
246
378
  * Web Apps launched via the attachment menu.
247
379
  */
248
380
  receiver?: WebAppUser;
381
+ /**
382
+ * An object containing data about the chat where the bot was launched via
383
+ * the attachment menu. Returned for supergroups, channels and group chats –
384
+ * only for Web Apps launched via the attachment menu.
385
+ */
386
+ chat?: WebAppChat;
249
387
  /**
250
388
  * The value of the startattach parameter, passed via link. Only returned for
251
389
  * Web Apps when launched from the attachment menu via link. The value of the
@@ -254,6 +392,11 @@ interface WebAppInitData {
254
392
  * away.
255
393
  */
256
394
  start_param?: string;
395
+ /**
396
+ * Time in seconds, after which a message can be sent via the
397
+ * answerWebAppQuery method.
398
+ */
399
+ can_send_after?: number;
257
400
  /** Unix time when the form was opened. */
258
401
  auth_date: number;
259
402
  /**
@@ -289,3 +432,34 @@ interface WebAppUser {
289
432
  */
290
433
  photo_url?: string;
291
434
  }
435
+
436
+ /**
437
+ * This object represents a chat.
438
+ */
439
+ interface WebAppChat {
440
+ /**
441
+ * Unique identifier for this chat. This number may have more than 32
442
+ * significant bits and some programming languages may have
443
+ * difficulty/silent defects in interpreting it. But it has at most 52
444
+ * significant bits, so a signed 64-bit integer or double-precision float
445
+ * type are safe for storing this identifier.
446
+ */
447
+ id: number;
448
+ /**
449
+ * Type of chat, can be either “group”, “supergroup” or “channel”
450
+ */
451
+ type: 'group' | 'supergroup' | 'channel';
452
+ /**
453
+ * Title of the chat
454
+ */
455
+ title: string;
456
+ /**
457
+ * Username of the chat
458
+ */
459
+ username?: string;
460
+ /**
461
+ * URL of the chat’s photo. The photo can be in .jpeg or .svg formats. Only
462
+ * returned for Web Apps launched from the attachment menu.
463
+ */
464
+ photo_url?: string;
465
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/telegram-web-app",
3
- "version": "1.0.0",
3
+ "version": "1.0.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",
@@ -20,6 +20,6 @@
20
20
  },
21
21
  "scripts": {},
22
22
  "dependencies": {},
23
- "typesPublisherContentHash": "8d62315952a0efc30b1381ab61d025d615e9df2751d319c732ab50c2125be5d1",
24
- "typeScriptVersion": "3.9"
23
+ "typesPublisherContentHash": "bac4c92463a29523d87e9f18893207ba7d91af4599ea2b407d6682c7f70d0e47",
24
+ "typeScriptVersion": "4.0"
25
25
  }