@types/telegram-web-app 1.0.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,16 @@
1
+ # Installation
2
+ > `npm install --save @types/telegram-web-app`
3
+
4
+ # Summary
5
+ This package contains type definitions for telegram-web-app (https://telegram.org/js/telegram-web-app.js).
6
+
7
+ # Details
8
+ Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/telegram-web-app.
9
+
10
+ ### Additional Details
11
+ * Last updated: Mon, 25 Apr 2022 13:31:36 GMT
12
+ * Dependencies: none
13
+ * Global values: `Telegram`
14
+
15
+ # Credits
16
+ These definitions were written by [KnorpelSenf](https://github.com/KnorpelSenf).
@@ -0,0 +1,291 @@
1
+ // Type definitions for non-npm package telegram-web-app 1.0
2
+ // Project: https://telegram.org/js/telegram-web-app.js
3
+ // Definitions by: KnorpelSenf <https://github.com/KnorpelSenf>
4
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+
6
+ declare var Telegram: Telegram;
7
+
8
+ type Color = string | false;
9
+
10
+ interface Telegram {
11
+ WebApp: WebApp;
12
+ }
13
+
14
+ interface WebApp {
15
+ /**
16
+ * A string with raw data transferred to the Web App, convenient for
17
+ * validating data. WARNING: Validate data from this field before using it on
18
+ * the bot's server.
19
+ */
20
+ initData: string;
21
+ /**
22
+ * An object with input data transferred to the Web App. WARNING: Data from
23
+ * this field should not be trusted. You should only use data from initData on
24
+ * the bot's server and only after it has been validated.
25
+ */
26
+ initDataUnsafe: WebAppInitData;
27
+ /**
28
+ * The color scheme currently used in the Telegram app. Either “light” or
29
+ * “dark”. Also available as the CSS variable var(--tg-color-scheme).
30
+ */
31
+ colorScheme: 'light' | 'dark';
32
+ /**
33
+ * An object containing the current theme settings used in the Telegram app.
34
+ */
35
+ themeParams: ThemeParams;
36
+ /**
37
+ * True if the Web App is expanded to the maximum available height. False, if
38
+ * the Web App occupies part of the screen and can be expanded to the full
39
+ * height using the expand() method.
40
+ */
41
+ isExpanded: boolean;
42
+ /**
43
+ * The current height of the visible area of the Web App. Also available in
44
+ * CSS as the variable var(--tg-viewport-height).
45
+ *
46
+ * The application can display just the top part of the Web App, with its
47
+ * lower part remaining outside the screen area. From this position, the user
48
+ * can “pull” the Web App to its maximum height, while the bot can do the same
49
+ * by calling the expand() method. As the position of the Web App changes, the
50
+ * current height value of the visible area will be updated in real time.
51
+ *
52
+ * Please note that the refresh rate of this value is not sufficient to
53
+ * smoothly follow the lower border of the window. It should not be used to
54
+ * pin interface elements to the bottom of the visible area. It's more
55
+ * appropriate to use the value of the viewportStableHeight field for this
56
+ * purpose.
57
+ */
58
+ viewportHeight: number;
59
+ /**
60
+ * The height of the visible area of the Web App in its last stable state.
61
+ * Also available in CSS as a variable var(--tg-viewport-stable-height).
62
+ *
63
+ * The application can display just the top part of the Web App, with its
64
+ * lower part remaining outside the screen area. From this position, the user
65
+ * can “pull” the Web App to its maximum height, while the bot can do the same
66
+ * by calling the expand() method. Unlike the value of viewportHeight, the
67
+ * value of viewportStableHeight does not change as the position of the Web
68
+ * App changes with user gestures or during animations. The value of
69
+ * viewportStableHeight will be updated after all gestures and animations are
70
+ * completed and the Web App reaches its final size.
71
+ *
72
+ * Note the event viewportChanged with the passed parameter
73
+ * isStateStable=true, which will allow you to track when the stable state of
74
+ * the height of the visible area changes.
75
+ */
76
+ viewportStableHeight: number;
77
+ /**
78
+ * An object for controlling the main button, which is displayed at the bottom
79
+ * of the Web App in the Telegram interface.
80
+ */
81
+ MainButton: MainButton;
82
+ /**
83
+ * A method that sets the app event handler. Check the list of available
84
+ * events.
85
+ */
86
+ onEvent(eventType: 'themeChanged' | 'mainButtonClicked', eventHandler: () => void): void;
87
+ onEvent(eventType: 'viewPortChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
88
+ /** A method that deletes a previously set event handler. */
89
+ offEvent(eventType: 'themeChanged' | 'mainButtonClicked', eventHandler: () => void): void;
90
+ offEvent(eventType: 'viewPortChanged', eventHandler: (eventData: { isStateStable: boolean }) => void): void;
91
+ /**
92
+ * A method used to send data to the bot. When this method is called, a
93
+ * service message is sent to the bot containing the data data of the length
94
+ * up to 4096 bytes, and the Web App is closed. See the field web_app_data in
95
+ * the class Message.
96
+ *
97
+ * This method is only available for Web Apps launched via a Keyboard button.
98
+ */
99
+ sendData(data: string): void;
100
+ /**
101
+ * A method that informs the Telegram app that the Web App is ready to be
102
+ * displayed. It is recommended to call this method as early as possible, as
103
+ * soon as all essential interface elements are loaded. Once this method is
104
+ * called, the loading placeholder is hidden and the Web App is shown. If the
105
+ * method is not called, the placeholder will be hidden only when the page is
106
+ * fully loaded.
107
+ */
108
+ ready(): void;
109
+ /**
110
+ * A method that expands the Web App to the maximum available height. To find
111
+ * out if the Web App is expanded to the maximum height, refer to the value of
112
+ * the Telegram.WebApp.isExpanded parameter
113
+ */
114
+ expand(): void;
115
+ /** A method that closes the Web App. */
116
+ close(): void;
117
+ }
118
+
119
+ /**
120
+ * Web Apps can adjust the appearance of the interface to match the Telegram
121
+ * user's app in real time. This object contains the user's current theme
122
+ * settings:
123
+ */
124
+ interface ThemeParams {
125
+ /**
126
+ * Background color in the #RRGGBB format. Also available as the CSS variable
127
+ * var(--tg-theme-bg-color).
128
+ */
129
+ bg_color: string;
130
+ /**
131
+ * Main text color in the #RRGGBB format. Also available as the CSS variable
132
+ * var(--tg-theme-text-color).
133
+ */
134
+ text_color: string;
135
+ /**
136
+ * Hint text color in the #RRGGBB format. Also available as the CSS variable
137
+ * var(--tg-theme-hint-color).
138
+ */
139
+ hint_color: string;
140
+ /**
141
+ * Link color in the #RRGGBB format. Also available as the CSS variable
142
+ * var(--tg-theme-link-color).
143
+ */
144
+ link_color: string;
145
+ /**
146
+ * Button color in the #RRGGBB format. Also available as the CSS variable
147
+ * var(--tg-theme-button-color).
148
+ */
149
+ button_color: string;
150
+ /**
151
+ * Button text color in the #RRGGBB format. Also available as the CSS variable
152
+ * var(--tg-theme-button-text-color).
153
+ */
154
+ button_text_color: string;
155
+ }
156
+
157
+ /**
158
+ * This object controls the main button, which is displayed at the bottom of the
159
+ * Web App in the Telegram interface.
160
+ */
161
+ interface MainButton {
162
+ /** Current button text. Set to CONTINUE by default. */
163
+ text: string;
164
+ /** Current button color. Set to themeParams.button_color by default. */
165
+ color: string;
166
+ /**
167
+ * Current button text color. Set to themeParams.button_text_color by default.
168
+ */
169
+ textColor: string;
170
+ /** Shows whether the button is visible. Set to false by default. */
171
+ isVisible: boolean;
172
+ /** Shows whether the button is active. Set to true by default. */
173
+ isActive: boolean;
174
+ /** Readonly. Shows whether the button is displaying a loading indicator. */
175
+ isProgressVisible: boolean;
176
+ /** A method to set the button text. */
177
+ setText(text: string): MainButton;
178
+ /**
179
+ * A method that sets the button press event handler. An alias for
180
+ * Telegram.WebApp.onEvent('mainButtonClicked', callback)
181
+ */
182
+ onClick(callback: () => void): MainButton;
183
+ /** A method that deletes a previously set handler */
184
+ offClick(callback: () => void): MainButton;
185
+ /**
186
+ * A method to make the button visible. Note that opening the Web App from the
187
+ * attachment menu hides the main button until the user interacts with the
188
+ * Web App interface.
189
+ */
190
+ show(): MainButton;
191
+ /** A method to hide the button. */
192
+ hide(): MainButton;
193
+ /** A method to enable the button. */
194
+ enable(): MainButton;
195
+ /** A method to disable the button. */
196
+ disable(): MainButton;
197
+ /**
198
+ * A method to show a loading indicator on the button. It is recommended to
199
+ * display loading progress if the action tied to the button may take a long
200
+ * time. By default, the button is disabled while the action is in progress.
201
+ * If the parameter leaveActive=true is passed, the button remains enabled.
202
+ */
203
+ showProgress(leaveActive?: boolean): MainButton;
204
+ /** A method to hide the loading indicator. */
205
+ hideProgress(): MainButton;
206
+ /**
207
+ * A method to set the button parameters. The params parameter is an object
208
+ * containing one or several fields that need to be changed:
209
+ * - text - button text;
210
+ * - color - button color;
211
+ * - text_color - button text color;
212
+ * - is_active - enable the button;
213
+ * - is_visible - show the button.
214
+ */
215
+ setParams(params: MainButtonParams): MainButton;
216
+ }
217
+
218
+ interface MainButtonParams {
219
+ /** button text */
220
+ text?: string;
221
+ /** button color */
222
+ color?: Color;
223
+ /** button text color */
224
+ text_color?: Color;
225
+ /** enable the button */
226
+ is_active?: boolean;
227
+ /** show the button */
228
+ is_visible?: boolean;
229
+ }
230
+
231
+ /**
232
+ * This object contains data that is transferred to the Web App when it is
233
+ * opened. It is empty if the Web App was launched from a keyboard button.
234
+ */
235
+ interface WebAppInitData {
236
+ /**
237
+ * A unique identifier for the Web App session, required for sending messages
238
+ * via the answerWebAppQuery method.
239
+ */
240
+ query_id?: string;
241
+ /** An object containing data about the current user. */
242
+ user?: WebAppUser;
243
+ /**
244
+ * An object containing data about the chat partner of the current user in the
245
+ * chat where the bot was launched via the attachment menu. Returned only for
246
+ * Web Apps launched via the attachment menu.
247
+ */
248
+ receiver?: WebAppUser;
249
+ /**
250
+ * The value of the startattach parameter, passed via link. Only returned for
251
+ * Web Apps when launched from the attachment menu via link. The value of the
252
+ * start_param parameter will also be passed in the GET-parameter
253
+ * tgWebAppStartParam, so the Web App can load the correct interface right
254
+ * away.
255
+ */
256
+ start_param?: string;
257
+ /** Unix time when the form was opened. */
258
+ auth_date: number;
259
+ /**
260
+ * A hash of all passed parameters, which the bot server can use to check
261
+ * their validity.
262
+ */
263
+ hash: string;
264
+ }
265
+
266
+ /** This object contains the data of the Web App user. */
267
+ interface WebAppUser {
268
+ /**
269
+ * A unique identifier for the user or bot. This number may have more than 32
270
+ * significant bits and some programming languages may have difficulty/silent
271
+ * defects in interpreting it. It has at most 52 significant bits, so a 64-bit
272
+ * integer or a double-precision float type is safe for storing this
273
+ * identifier.
274
+ */
275
+ id: number;
276
+ /** True, if this user is a bot. Returns in the receiver field only. */
277
+ is_bot?: boolean;
278
+ /** First name of the user or bot. */
279
+ first_name: string;
280
+ /** Last name of the user or bot. */
281
+ last_name?: string;
282
+ /** Username of the user or bot. */
283
+ username?: string;
284
+ /** IETF language tag of the user's language. Returns in user field only. */
285
+ language_code?: string;
286
+ /**
287
+ * URL of the user’s profile photo. The photo can be in .jpeg or .svg formats.
288
+ * Only returned for Web Apps launched from the attachment menu.
289
+ */
290
+ photo_url?: string;
291
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@types/telegram-web-app",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript definitions for telegram-web-app",
5
+ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/telegram-web-app",
6
+ "license": "MIT",
7
+ "contributors": [
8
+ {
9
+ "name": "KnorpelSenf",
10
+ "url": "https://github.com/KnorpelSenf",
11
+ "githubUsername": "KnorpelSenf"
12
+ }
13
+ ],
14
+ "main": "",
15
+ "types": "index.d.ts",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
19
+ "directory": "types/telegram-web-app"
20
+ },
21
+ "scripts": {},
22
+ "dependencies": {},
23
+ "typesPublisherContentHash": "8d62315952a0efc30b1381ab61d025d615e9df2751d319c732ab50c2125be5d1",
24
+ "typeScriptVersion": "3.9"
25
+ }