@types/telegram-web-app 6.7.0 → 6.9.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.
telegram-web-app/LICENSE CHANGED
File without changes
@@ -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: Wed, 26 Apr 2023 21:02:48 GMT
11
+ * Last updated: Tue, 26 Sep 2023 22:35:04 GMT
12
12
  * Dependencies: none
13
13
  * Global values: `Telegram`
14
14
 
@@ -1,4 +1,4 @@
1
- // Type definitions for non-npm package telegram-web-app 6.7
1
+ // Type definitions for non-npm package telegram-web-app 6.9
2
2
  // Project: https://telegram.org/js/telegram-web-app.js
3
3
  // Definitions by: KnorpelSenf <https://github.com/KnorpelSenf>
4
4
  // MKRhere <https://github.com/MKRhere>
@@ -111,23 +111,25 @@ interface WebApp {
111
111
  * An object for controlling haptic feedback.
112
112
  */
113
113
  HapticFeedback: HapticFeedback;
114
+ /**
115
+ * An object for controlling cloud storage.
116
+ */
117
+ CloudStorage: CloudStorage;
114
118
  /**
115
119
  * Returns true if the user's app supports a version of the Bot API that is
116
120
  * equal to or higher than the version passed as the parameter.
117
121
  */
118
122
  isVersionAtLeast(version: string): boolean;
119
123
  /**
120
- * A method that sets the app header color. You can only pass
121
- * Telegram.WebApp.themeParams.bg_color or
122
- * Telegram.WebApp.themeParams.secondary_bg_colo as a color or you can use
123
- * keywords bg_color, secondary_bg_color instead.
124
- */
125
- setHeaderColor(color: 'bg_color' | 'secondary_bg_color'): void;
124
+ * A method that sets the app header color in the `#RRGGBB` format.
125
+ * You can also use keywords bg_color and secondary_bg_color.
126
+ */ // string & {} prevents this from eagerly collapsing into just string
127
+ setHeaderColor(color: 'bg_color' | 'secondary_bg_color' | (string & {})): void;
126
128
  /**
127
- * A method that sets the app background color in the #RRGGBB format or you
128
- * can use keywords bg_color, secondary_bg_color instead.
129
+ * A method that sets the app background color in the `#RRGGBB` format or
130
+ * you can use keywords bg_color, secondary_bg_color instead.
129
131
  */
130
- setBackgroundColor(color: 'bg_color' | 'secondary_bg_color' | string): void;
132
+ setBackgroundColor(color: 'bg_color' | 'secondary_bg_color' | (string & {})): void;
131
133
  /**
132
134
  * A method that enables a confirmation dialog while the user is trying to close the Web App.
133
135
  */
@@ -146,9 +148,17 @@ interface WebApp {
146
148
  ): void;
147
149
  onEvent(eventType: 'popupClosed', eventHandler: (eventData: { button_id: string | null }) => void): void;
148
150
  onEvent(eventType: 'viewportChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
149
- onEvent(eventType: 'invoiceClosed', eventHandler: (eventData: { url: string, status: 'paid' | 'cancelled' | 'failed' | 'pending' }) => void): void;
151
+ onEvent(
152
+ eventType: 'invoiceClosed',
153
+ eventHandler: (eventData: { url: string; status: 'paid' | 'cancelled' | 'failed' | 'pending' }) => void,
154
+ ): void;
150
155
  onEvent(eventType: 'qrTextReceived', eventHandler: (eventData: { data: string }) => void): void;
151
156
  onEvent(eventType: 'clipboardTextReceived', eventHandler: (eventData: { data: string | null }) => void): void;
157
+ onEvent(
158
+ eventType: 'writeAccessRequested',
159
+ eventHandler: (eventData: { status: 'allowed' | 'cancelled' }) => void,
160
+ ): void;
161
+ onEvent(eventType: 'contactRequested', eventHandler: (eventData: { status: 'sent' | 'cancelled' }) => void): void;
152
162
 
153
163
  /** A method that deletes a previously set event handler. */
154
164
  offEvent(
@@ -157,9 +167,17 @@ interface WebApp {
157
167
  ): void;
158
168
  offEvent(eventType: 'popupClosed', eventHandler: (eventData: { button_id: string | null }) => void): void;
159
169
  offEvent(eventType: 'viewportChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
160
- offEvent(eventType: 'invoiceClosed', eventHandler: (eventData: { url: string, status: 'paid' | 'cancelled' | 'failed' | 'pending' }) => void): void;
170
+ offEvent(
171
+ eventType: 'invoiceClosed',
172
+ eventHandler: (eventData: { url: string; status: 'paid' | 'cancelled' | 'failed' | 'pending' }) => void,
173
+ ): void;
161
174
  offEvent(eventType: 'qrTextReceived', eventHandler: (eventData: { data: string }) => void): void;
162
175
  offEvent(eventType: 'clipboardTextReceived', eventHandler: (eventData: { data: string | null }) => void): void;
176
+ offEvent(
177
+ eventType: 'writeAccessRequested',
178
+ eventHandler: (eventData: { status: 'allowed' | 'cancelled' }) => void,
179
+ ): void;
180
+ offEvent(eventType: 'contactRequested', eventHandler: (eventData: { status: 'sent' | 'cancelled' }) => void): void;
163
181
 
164
182
  /**
165
183
  * A method used to send data to the bot. When this method is called, a
@@ -200,7 +218,10 @@ interface WebApp {
200
218
  * optional callback parameter was passed, the callback function will be
201
219
  * called and the invoice status will be passed as the first argument.
202
220
  */
203
- openInvoice(url: string, callback: (url: string, status: 'paid' | 'cancelled' | 'failed' | 'pending') => void): void;
221
+ openInvoice(
222
+ url: string,
223
+ callback: (url: string, status: 'paid' | 'cancelled' | 'failed' | 'pending') => void,
224
+ ): void;
204
225
  /**
205
226
  * A method that shows a native popup described by the params argument of the type PopupParams.
206
227
  * The Web App will receive the event popupClosed when the popup is closed. If an optional
@@ -241,6 +262,26 @@ interface WebApp {
241
262
  * in response to a user interaction with the Web App interface (e.g. a click inside the Web App or on the main button).
242
263
  */
243
264
  readTextFromClipboard(callback?: (data: string | null) => void): void;
265
+ /**
266
+ * A method that shows a native popup requesting permission for the bot to
267
+ * send messages to the user.
268
+ *
269
+ * @param callback If an optional callback parameter was passed, the
270
+ * callback function will be called when the popup is closed and the first
271
+ * argument will be a boolean indicating whether the user granted this
272
+ * access.
273
+ */
274
+ requestWriteAccess(callback?: (success: boolean) => void): void;
275
+ /**
276
+ * A method that shows a native popup prompting the user for their phone
277
+ * number.
278
+ *
279
+ * @param callback If an optional callback parameter was passed, the
280
+ * callback function will be called when the popup is closed and the first
281
+ * argument will be a boolean indicating whether the user shared its
282
+ * phone number.
283
+ */
284
+ requestContact(callback?: (success: boolean) => void): void;
244
285
  /**
245
286
  * A method that informs the Telegram app that the Web App is ready to be
246
287
  * displayed. It is recommended to call this method as early as possible, as
@@ -494,6 +535,86 @@ interface HapticFeedback {
494
535
  selectionChanged(): void;
495
536
  }
496
537
 
538
+ interface CloudStorage {
539
+ /**
540
+ * A method that stores a value in the cloud storage using the
541
+ * specified key.
542
+ *
543
+ * @param key The key should contain 1-128 characters, only A-Z, a-z, 0-9,
544
+ * _ and - are allowed.
545
+ * @param value The value should contain 0-4096 characters. You can store
546
+ * up to 1024 keys in the cloud storage.
547
+ * @param callback If an optional callback parameter was passed, the
548
+ * callback function will be called. In case of an error, the first argument
549
+ * will contain the error. In case of success, the first argument will be
550
+ * null and the second argument will be a boolean indicating whether the
551
+ * value was stored.
552
+ */
553
+ setItem(key: string, value: string, callback?: (error: string | null, success: null | true) => void): CloudStorage;
554
+ /**
555
+ * A method that receives a value from the cloud storage using
556
+ * the specified key.
557
+ *
558
+ * @param key The key should contain 1-128 characters, only A-Z, a-z, 0-9,
559
+ * _ and - are allowed.
560
+ * @param callback In case of an error, the callback function will
561
+ * be called and the first argument will contain the error. In case of
562
+ * success, the first argument will be null and the value will be passed
563
+ * as the second argument.
564
+ */
565
+ getItem(key: string, callback?: (error: string | null, value: null | string) => void): CloudStorage;
566
+ /**
567
+ * A method that receives values from the cloud storage using the specified
568
+ * keys.
569
+ *
570
+ * @param key The keys should contain 1-128 characters, only A-Z, a-z, 0-9,
571
+ * _ and - are allowed.
572
+ * @param callback In case of an error, the callback? function will be
573
+ * called and the first argument will contain the error. In case of
574
+ * success, the first argument will be null and the values will be passed
575
+ * as the second argument.
576
+ */
577
+ getItems(
578
+ keys: string[],
579
+ callback?: (error: string | null, values: null | Record<string, string>) => void,
580
+ ): CloudStorage;
581
+ /**
582
+ * A method that removes a value from the cloud storage using the specified
583
+ * key.
584
+ *
585
+ * @param key The key should contain 1-128 characters, only A-Z, a-z, 0-9,
586
+ * _ and - are allowed.
587
+ * @param callback If an optional callback parameter was passed, the
588
+ * callback function will be called. In case of an error, the first
589
+ * argument will contain the error. In case of success, the first
590
+ * argument will be null and the second argument will be a boolean
591
+ * indicating whether the value was removed.
592
+ */
593
+ removeItem(key: string, callback?: (error: string | null, success: null | true) => void): CloudStorage;
594
+ /**
595
+ * A method that removes values from the cloud storage using the specified
596
+ * keys.
597
+ *
598
+ * @param key The keys should contain 1-128 characters, only A-Z, a-z, 0-9,
599
+ * _ and - are allowed.
600
+ * @param callback If an optional callback parameter was passed, the
601
+ * callback function will be called. In case of an error, the first
602
+ * argument will contain the error. In case of success, the first
603
+ * argument will be null and the second argument will be a boolean
604
+ * indicating whether the values were removed.
605
+ */
606
+ removeItems(keys: string[], callback?: (error: string | null, success: null | true) => void): CloudStorage;
607
+ /**
608
+ * A method that receives the list of all keys stored in the cloud storage.
609
+ *
610
+ * @param callback In case of an error, the callback function will be called
611
+ * and the first argument will contain the error. In case of success, the
612
+ * first argument will be null and the list of keys will be passed as the
613
+ * second argument.
614
+ */
615
+ getKeys(callback?: (error: string | null, keys: null | string[]) => void): CloudStorage;
616
+ }
617
+
497
618
  /**
498
619
  * This object contains data that is transferred to the Web App when it is
499
620
  * opened. It is empty if the Web App was launched from a keyboard button.
@@ -574,6 +695,10 @@ interface WebAppUser {
574
695
  language_code?: string;
575
696
  /** True, if this user is a Telegram Premium user. */
576
697
  is_premium?: true;
698
+ /** True, if this user added the bot to the attachment menu. */
699
+ added_to_attachment_menu?: true;
700
+ /** True, if this user allowed the bot to message them. */
701
+ allows_write_to_pm?: true;
577
702
  /**
578
703
  * URL of the user’s profile photo. The photo can be in .jpeg or .svg formats.
579
704
  * 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": "6.7.0",
3
+ "version": "6.9.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",
@@ -30,6 +30,6 @@
30
30
  },
31
31
  "scripts": {},
32
32
  "dependencies": {},
33
- "typesPublisherContentHash": "087c84405ec21f5ea2663c05b6ff92799f58e740cd633c419e95f197342d36bc",
34
- "typeScriptVersion": "4.3"
33
+ "typesPublisherContentHash": "2f5a5fcf817fe0bf0a0e10016c001674a72d56fe50e45e2ee126f9db11c37afb",
34
+ "typeScriptVersion": "4.5"
35
35
  }