├── .prettierrc ├── .eslintignore ├── .gitignore ├── .npmignore ├── .eslintrc ├── tsconfig.json ├── .github └── workflows │ ├── release.yml │ └── prerelease.yml ├── package.json ├── LICENSE ├── Readme.md └── index.ts /.prettierrc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | node_modules/ 3 | *.log -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | node_modules/ 3 | tsconfig.json 4 | .eslintrc 5 | .eslintignore 6 | .prettierrc 7 | .gitignore 8 | *.log 9 | .github/ -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["plugin:@typescript-eslint/recommended", "prettier"], 3 | "parser": "@typescript-eslint/parser", 4 | "env": { 5 | "node": false, 6 | "browser": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "esnext"], 5 | "strict": true, 6 | "module": "esnext", 7 | "moduleResolution": "Node", 8 | "declaration": true 9 | }, 10 | "files": ["index.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | release: 4 | types: [released] 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | contents: read 10 | id-token: write 11 | steps: 12 | - uses: actions/checkout@v4 13 | # Setup .npmrc file to publish to npm 14 | - uses: actions/setup-node@v4 15 | with: 16 | node-version: '18.x' 17 | registry-url: 'https://registry.npmjs.org' 18 | - run: npm ci 19 | - run: npm publish --access public 20 | env: 21 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/prerelease.yml: -------------------------------------------------------------------------------- 1 | name: Prerelease 2 | on: 3 | release: 4 | types: [prereleased] 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | contents: read 10 | id-token: write 11 | steps: 12 | - uses: actions/checkout@v4 13 | # Setup .npmrc file to publish to npm 14 | - uses: actions/setup-node@v4 15 | with: 16 | node-version: '18.x' 17 | registry-url: 'https://registry.npmjs.org' 18 | - run: npm ci 19 | - run: npm publish --access public --tag beta 20 | env: 21 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@twa-dev/types", 3 | "version": "8.0.2", 4 | "main": "index.js", 5 | "description": "Types for Telegram Web Apps (TWA) SDK", 6 | "keywords": [ 7 | "telegram", 8 | "typescript", 9 | "ts", 10 | "types", 11 | "telegram web apps", 12 | "telegram bot", 13 | "bot" 14 | ], 15 | "repository": "https://github.com/twa-dev/types.git", 16 | "author": "Artur Stambultsian ", 17 | "license": "MIT", 18 | "devDependencies": { 19 | "@typescript-eslint/eslint-plugin": "^5.33.0", 20 | "@typescript-eslint/parser": "^5.33.0", 21 | "eslint": "^8.21.0", 22 | "eslint-config-prettier": "^8.5.0", 23 | "prettier": "^2.7.1", 24 | "typescript": "^4.7.4" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Artur Stambultsian 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. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ## Types 2 | 3 | [![npm version](https://img.shields.io/npm/v/@twa-dev/types)](https://www.npmjs.com/package/@twa-dev/types) 4 | 5 | Types for [Telegram Web Apps (TWA)](https://core.telegram.org/bots/webapps) SDK. 6 | 7 | ![ts_AdobeExpress (2)](https://user-images.githubusercontent.com/5061840/184690893-d875b355-f8d3-44e8-824c-eb7728e89768.gif) 8 | 9 | ### Installation 10 | 11 | ``` 12 | npm i @twa-dev/types 13 | ``` 14 | 15 | ### Usage Example 16 | 17 | ```ts 18 | import { Telegram } from "@twa-dev/types"; 19 | 20 | declare global { 21 | interface Window { 22 | Telegram: Telegram; 23 | } 24 | } 25 | 26 | window.Telegram.WebApp.HapticFeedback.notificationOccurred("success"); 27 | ``` 28 | 29 | ### Exported Types 30 | 31 | - [`WebAppUser`](https://core.telegram.org/bots/webapps#webappuser) 32 | - [`WebAppChat`](https://core.telegram.org/bots/webapps#webappchat) 33 | - [`WebAppInitData`](https://core.telegram.org/bots/webapps#webappinitdata) 34 | - [`ThemeParams`](https://core.telegram.org/bots/webapps#themeparams) 35 | - [`HapticFeedback`](https://core.telegram.org/bots/webapps#hapticfeedback) 36 | - [`BackButton`](https://core.telegram.org/bots/webapps#backbutton) 37 | - [`BottomButton`](https://core.telegram.org/bots/webapps#bottombutton) 38 | - `MainButton` 39 | - `SecondaryButton` 40 | - [`SettingsButton`](https://core.telegram.org/bots/webapps#settingsbutton) 41 | - [`EventNames`](https://core.telegram.org/bots/webapps#events-available-for-web-apps) 42 | - [`EventParams`](https://core.telegram.org/bots/webapps#events-available-for-web-apps) 43 | - [`PopupParams`](https://core.telegram.org/bots/webapps#popupparams) 44 | - [`PopupButton`](https://core.telegram.org/bots/webapps#popupbutton) 45 | - [`WebApp`](https://core.telegram.org/bots/webapps#initializing-web-apps) 46 | - [`ScanQrPopupParams`](https://core.telegram.org/bots/webapps#scanqrpopupparams) 47 | - [`CloudStorage`](https://core.telegram.org/bots/webapps#cloudstorage) 48 | - [`BiometricManager`](https://core.telegram.org/bots/webapps#biometricmanager) 49 | - [`BiometricRequestAccessParams`](https://core.telegram.org/bots/webapps#biometricrequestaccessparams) 50 | - [`BiometricAuthenticateParams`](https://core.telegram.org/bots/webapps#biometricauthenticateparams) 51 | - [`StoryShareParams`](https://core.telegram.org/bots/webapps#storyshareparams) 52 | - [`StoryWidgetLink`](https://core.telegram.org/bots/webapps#storywidgetlink) 53 | - [`Accelerometer`](https://core.telegram.org/bots/webapps#accelerometer) 54 | - [`DeviceOrientation`](https://core.telegram.org/bots/webapps#deviceorientation) 55 | - [`DeviceOrientationStartParams`](https://core.telegram.org/bots/webapps#deviceorientationstartparams) 56 | - [`Gyroscope`](https://core.telegram.org/bots/webapps#gyroscope) 57 | - [`GyroscopeStartParams`](https://core.telegram.org/bots/webapps#gyroscopestartparams) 58 | - [`LocationManager`](https://core.telegram.org/bots/webapps#locationmanager) 59 | - [`LocationData`](https://core.telegram.org/bots/webapps#locationdata) 60 | - [`SafeAreaInset`](https://core.telegram.org/bots/webapps#safeareainset) 61 | - [`ContentSafeAreaInset`](https://core.telegram.org/bots/webapps#contentsafeareainset) 62 | - [`EmojiStatusParams`](https://core.telegram.org/bots/webapps#emojistatusparams) 63 | - [`DownloadFileParams`](https://core.telegram.org/bots/webapps#downloadfileparams) 64 | - `Platforms` 65 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | export interface WebAppUser { 2 | id: number; 3 | is_bot?: boolean; 4 | first_name: string; 5 | last_name?: string; 6 | username?: string; 7 | language_code?: string; 8 | is_premium?: boolean; 9 | photo_url?: string; 10 | } 11 | 12 | export interface WebAppChat { 13 | id: number; 14 | type: "group" | "supergroup" | "channel"; 15 | title: string; 16 | username?: string; 17 | photo_url?: string; 18 | } 19 | 20 | export interface WebAppInitData { 21 | query_id?: string; 22 | auth_date: number; 23 | hash: string; 24 | user?: WebAppUser & { 25 | added_to_attachment_menu?: boolean; 26 | allows_write_to_pm?: boolean; 27 | }; 28 | receiver?: WebAppUser; 29 | start_param?: string; 30 | can_send_after?: number; 31 | chat?: WebAppChat; 32 | chat_type?: "sender" | "private" | "group" | "supergroup" | "channel"; 33 | chat_instance?: string; 34 | signature: string; 35 | } 36 | 37 | export interface ThemeParams { 38 | bg_color: `#${string}`; 39 | secondary_bg_color: `#${string}`; 40 | text_color: `#${string}`; 41 | hint_color: `#${string}`; 42 | link_color: `#${string}`; 43 | button_color: `#${string}`; 44 | button_text_color: `#${string}`; 45 | header_bg_color: `#${string}`; 46 | accent_text_color: `#${string}`; 47 | section_bg_color: `#${string}`; 48 | section_header_text_color: `#${string}`; 49 | subtitle_text_color: `#${string}`; 50 | destructive_text_color: `#${string}`; 51 | section_separator_color: `#${string}`; 52 | bottom_bar_bg_color: `#${string}`; 53 | } 54 | 55 | export interface HapticFeedback { 56 | impactOccurred: ( 57 | style: "light" | "medium" | "heavy" | "rigid" | "soft" 58 | ) => HapticFeedback; 59 | notificationOccurred: ( 60 | type: "error" | "success" | "warning" 61 | ) => HapticFeedback; 62 | selectionChanged: () => HapticFeedback; 63 | } 64 | 65 | type CloudStorageKey = string; 66 | type CloudStorageValue = string; 67 | 68 | interface CloudStorageItems { 69 | [key: CloudStorageKey]: CloudStorageValue; 70 | } 71 | 72 | export interface CloudStorage { 73 | setItem: ( 74 | key: CloudStorageKey, 75 | value: CloudStorageValue, 76 | callback?: (error: string | null, result?: boolean) => unknown 77 | ) => void; 78 | getItem: ( 79 | key: CloudStorageKey, 80 | callback?: (error: string | null, result?: CloudStorageValue) => unknown 81 | ) => void; 82 | getItems: ( 83 | keys: Array, 84 | callback?: (error: string | null, result?: CloudStorageItems) => unknown 85 | ) => void; 86 | getKeys: ( 87 | callback?: ( 88 | error: string | null, 89 | result?: Array 90 | ) => unknown 91 | ) => void; 92 | removeItem: ( 93 | key: CloudStorageKey, 94 | callback?: (error: string | null, result?: boolean) => unknown 95 | ) => void; 96 | removeItems: ( 97 | key: Array, 98 | callback?: (error: string | null, result?: boolean) => unknown 99 | ) => void; 100 | } 101 | 102 | export type Contact = { 103 | first_name?: string; 104 | last_name?: string; 105 | phone_number: string; 106 | user_id: number; 107 | }; 108 | 109 | export type RequestContactResponse = 110 | | { 111 | status: "sent"; 112 | response: string; 113 | hash: string; 114 | responseUnsafe: { 115 | auth_date: string; 116 | contact: Contact; 117 | }; 118 | } 119 | | { 120 | status: "cancelled"; 121 | }; 122 | 123 | export interface BackButton { 124 | isVisible: boolean; 125 | show: () => BackButton; 126 | hide: () => BackButton; 127 | onClick: (cb: VoidFunction) => BackButton; 128 | offClick: (cb: VoidFunction) => BackButton; 129 | } 130 | 131 | type BottomButtonParams = { 132 | color?: string; 133 | text?: string; 134 | text_color?: string; 135 | is_active?: boolean; 136 | is_visible?: boolean; 137 | has_shine_effect?: boolean; 138 | }; 139 | 140 | export interface BottomButton { 141 | isActive: boolean; 142 | isVisible: boolean; 143 | isProgressVisible: boolean; 144 | text: string; 145 | color: `#${string}`; 146 | textColor: `#${string}`; 147 | show: () => BottomButton; 148 | hide: () => BottomButton; 149 | enable: () => BottomButton; 150 | disable: () => BottomButton; 151 | hideProgress: () => BottomButton; 152 | showProgress: (leaveActive?: boolean) => BottomButton; 153 | onClick: (callback: VoidFunction) => BottomButton; 154 | offClick: (callback: VoidFunction) => BottomButton; 155 | setText: (text: string) => BottomButton; 156 | setParams: (params: BottomButtonParams) => BottomButton; 157 | hasShineEffect: string; 158 | } 159 | 160 | export type MainButton = BottomButton; 161 | 162 | export interface SecondaryButton extends BottomButton { 163 | position: "top" | "left" | "bottom" | "right"; 164 | setParams: ( 165 | params: BottomButtonParams & { 166 | position?: SecondaryButton["position"]; 167 | } 168 | ) => SecondaryButton; 169 | } 170 | 171 | export interface SettingsButton { 172 | isVisible: boolean; 173 | onClick: (callback: VoidFunction) => SettingsButton; 174 | offClick: (callback: VoidFunction) => SettingsButton; 175 | show: () => SettingsButton; 176 | hide: () => SettingsButton; 177 | } 178 | 179 | export type InvoiceStatuses = "pending" | "failed" | "cancelled" | "paid"; 180 | 181 | export type EventNames = 182 | | "invoiceClosed" 183 | | "settingsButtonClicked" 184 | | "backButtonClicked" 185 | | "mainButtonClicked" 186 | | "secondaryButtonClicked" 187 | | "viewportChanged" 188 | | "themeChanged" 189 | | "popupClosed" 190 | | "qrTextReceived" 191 | | "clipboardTextReceived" 192 | | "writeAccessRequested" 193 | | "contactRequested" 194 | | "scanQrPopupClosed" 195 | | "activated" 196 | | "deactivated" 197 | | "safeAreaChanged" 198 | | "contentSafeAreaChanged" 199 | | "fullscreenChanged" 200 | | "fullscreenFailed" 201 | | "homeScreenAdded" 202 | | "homeScreenChecked" 203 | | "accelerometerStarted" 204 | | "accelerometerStopped" 205 | | "accelerometerChanged" 206 | | "accelerometerFailed" 207 | | "deviceOrientationStarted" 208 | | "deviceOrientationStopped" 209 | | "deviceOrientationChanged" 210 | | "deviceOrientationFailed" 211 | | "gyroscopeStarted" 212 | | "gyroscopeStopped" 213 | | "gyroscopeChanged" 214 | | "gyroscopeFailed" 215 | | "locationManagerUpdated" 216 | | "locationRequested" 217 | | "shareMessageSent" 218 | | "shareMessageFailed" 219 | | "emojiStatusSet" 220 | | "emojiStatusFailed" 221 | | "emojiStatusAccessRequested" 222 | | "fileDownloadRequested"; 223 | 224 | export type EventParams = { 225 | invoiceClosed: { url: string; status: InvoiceStatuses }; 226 | settingsButtonClicked: void; 227 | backButtonClicked: void; 228 | mainButtonClicked: void; 229 | secondaryButtonClicked: void; 230 | viewportChanged: { isStateStable: boolean }; 231 | themeChanged: void; 232 | popupClosed: { button_id: string | null }; 233 | qrTextReceived: { data: string }; 234 | clipboardTextReceived: { data: string }; 235 | writeAccessRequested: { status: "allowed" | "cancelled" }; 236 | contactRequested: { status: "sent" | "cancelled" }; 237 | scanQrPopupClosed: void; 238 | activated: void; 239 | deactivated: void; 240 | safeAreaChanged: void; 241 | contentSafeAreaChanged: void; 242 | fullscreenChanged: void; 243 | fullscreenFailed: { error: "UNSUPPORTED" | "ALREADY_FULLSCREEN" }; 244 | homeScreenAdded: void; 245 | homeScreenChecked: { status: HomeScreenStatus }; 246 | accelerometerStarted: void; 247 | accelerometerStopped: void; 248 | accelerometerChanged: void; 249 | accelerometerFailed: { error: "UNSUPPORTED" }; 250 | deviceOrientationStarted: void; 251 | deviceOrientationStopped: void; 252 | deviceOrientationChanged: void; 253 | deviceOrientationFailed: { error: "UNSUPPORTED" }; 254 | gyroscopeStarted: void; 255 | gyroscopeStopped: void; 256 | gyroscopeChanged: void; 257 | gyroscopeFailed: { error: "UNSUPPORTED" }; 258 | locationManagerUpdated: void; 259 | locationRequested: { locationData: LocationData }; 260 | shareMessageSent: void; 261 | shareMessageFailed: { 262 | error: 263 | | "UNSUPPORTED" 264 | | "MESSAGE_EXPIRED" 265 | | "MESSAGE_SEND_FAILED" 266 | | "USER_DECLINED" 267 | | "UNKNOWN_ERROR"; 268 | }; 269 | emojiStatusSet: void; 270 | emojiStatusFailed: { 271 | error: 272 | | "UNSUPPORTED" 273 | | "SUGGESTED_EMOJI_INVALID" 274 | | "DURATION_INVALID" 275 | | "USER_DECLINED" 276 | | "SERVER_ERROR" 277 | | "UNKNOWN_ERROR"; 278 | }; 279 | emojiStatusAccessRequested: { status: "allowed" | "cancelled" }; 280 | fileDownloadRequested: { status: "downloading" | "cancelled" }; 281 | }; 282 | 283 | export type PopupParams = { 284 | title?: string; 285 | message: string; 286 | buttons?: PopupButton[]; 287 | }; 288 | 289 | export type PopupButton = { 290 | id?: string; 291 | } & ( 292 | | { 293 | type: "default" | "destructive"; 294 | text: string; 295 | } 296 | | { 297 | type: "ok" | "close" | "cancel"; 298 | } 299 | ); 300 | 301 | export type ScanQrPopupParams = { 302 | text?: string; 303 | }; 304 | 305 | export type Platforms = 306 | | "android" 307 | | "android_x" 308 | | "ios" 309 | | "macos" 310 | | "tdesktop" 311 | | "weba" 312 | | "webk" 313 | | "unigram" 314 | | "unknown"; 315 | 316 | export type BiometricRequestAccessParams = { 317 | reason?: string; 318 | }; 319 | 320 | export type BiometricAuthenticateParams = { 321 | reason?: string; 322 | }; 323 | 324 | export type AccelerometerStartParams = { 325 | refresh_rate?: number; 326 | }; 327 | 328 | export type Accelerometer = { 329 | isStarted: boolean; 330 | x: number; 331 | y: number; 332 | z: number; 333 | start: ( 334 | params: AccelerometerStartParams, 335 | callback?: (isStarted: boolean) => unknown 336 | ) => Accelerometer; 337 | stop: (callback?: (isStopped: boolean) => unknown) => Accelerometer; 338 | }; 339 | 340 | export type DeviceOrientationStartParams = { 341 | refresh_rate?: number; 342 | need_absolute?: boolean; 343 | }; 344 | 345 | export type DeviceOrientation = { 346 | isStarted: boolean; 347 | absolute: boolean; 348 | alpha: number; 349 | beta: number; 350 | gamma: number; 351 | start: ( 352 | params: DeviceOrientationStartParams, 353 | callback?: (isStarted: boolean) => unknown 354 | ) => DeviceOrientation; 355 | stop: (callback?: (isStopped: boolean) => unknown) => DeviceOrientation; 356 | }; 357 | 358 | export type GyroscopeStartParams = { 359 | refresh_rate?: number; 360 | }; 361 | 362 | export type Gyroscope = { 363 | isStarted: boolean; 364 | x: number; 365 | y: number; 366 | z: number; 367 | start: ( 368 | params: GyroscopeStartParams, 369 | callback?: (isStarted: boolean) => unknown 370 | ) => Gyroscope; 371 | stop: (callback?: (isStopped: boolean) => unknown) => Gyroscope; 372 | }; 373 | 374 | export type LocationData = { 375 | latitude: number; 376 | longitude: number; 377 | altitude: number; 378 | course: number; 379 | speed: number; 380 | horizontal_accuracy: number; 381 | vertical_accuracy: number; 382 | course_accuracy: number; 383 | speed_accuracy: number; 384 | }; 385 | 386 | export type LocationManager = { 387 | isInited: boolean; 388 | isLocationAvailable: boolean; 389 | isAccessRequested: boolean; 390 | isAccessGranted: boolean; 391 | init: (callback?: (isInitialized: boolean) => unknown) => LocationManager; 392 | getLocation: ( 393 | callback: (data: LocationData | null) => unknown 394 | ) => LocationManager; 395 | openSettings: () => LocationManager; 396 | }; 397 | 398 | export type BiometricManager = { 399 | isInited: boolean; 400 | isBiometricAvailable: boolean; 401 | biometricType: "finger" | "face" | "unknown"; 402 | isAccessRequested: boolean; 403 | isAccessGranted: boolean; 404 | isBiometricTokenSaved: boolean; 405 | deviceId: string; 406 | init: (callback?: VoidFunction) => BiometricManager; 407 | requestAccess: ( 408 | params: BiometricRequestAccessParams, 409 | callback?: (isAccessGranted: boolean) => unknown 410 | ) => BiometricManager; 411 | authenticate: ( 412 | params: BiometricAuthenticateParams, 413 | callback?: (isAuthenticated: boolean) => unknown 414 | ) => BiometricManager; 415 | updateBiometricToken: ( 416 | token: string, 417 | callback?: (isBiometricTokenUpdated: boolean) => unknown 418 | ) => BiometricManager; 419 | openSettings: () => BiometricManager; 420 | }; 421 | 422 | export type StoryWidgetLink = { 423 | url: string; 424 | name?: string; 425 | }; 426 | 427 | export type ShareStoryParams = { 428 | text?: string; 429 | widget_link?: StoryWidgetLink; 430 | }; 431 | 432 | export type SafeAreaInset = { 433 | top: number; 434 | bottom: number; 435 | left: number; 436 | right: number; 437 | }; 438 | 439 | export type ContentSafeAreaInset = SafeAreaInset; 440 | 441 | export type HomeScreenStatus = "unsupported" | "unknown" | "added" | "missed"; 442 | 443 | export type EmojiStatusParams = { 444 | duration?: number; 445 | }; 446 | 447 | export type DownloadFileParams = { 448 | url: string; 449 | file_name: string; 450 | }; 451 | 452 | export interface WebApp { 453 | isExpanded: boolean; 454 | viewportHeight: number; 455 | viewportStableHeight: number; 456 | platform: Platforms; 457 | headerColor: `#${string}`; 458 | backgroundColor: `#${string}`; 459 | isClosingConfirmationEnabled: boolean; 460 | themeParams: ThemeParams; 461 | initDataUnsafe: WebAppInitData; 462 | initData: string; 463 | colorScheme: "light" | "dark"; 464 | onEvent: ( 465 | eventName: T, 466 | callback: (params: EventParams[T]) => unknown 467 | ) => void; 468 | offEvent: ( 469 | eventName: T, 470 | callback: (params: EventParams[T]) => unknown 471 | ) => void; 472 | sendData: (data: unknown) => void; 473 | close: VoidFunction; 474 | expand: VoidFunction; 475 | MainButton: MainButton; 476 | SecondaryButton: SecondaryButton; 477 | HapticFeedback: HapticFeedback; 478 | CloudStorage: CloudStorage; 479 | openLink: (link: string, options?: { try_instant_view: boolean }) => void; 480 | openTelegramLink: (link: string) => void; 481 | BackButton: BackButton; 482 | SettingsButton: SettingsButton; 483 | version: string; 484 | isVersionAtLeast: (version: string) => boolean; 485 | openInvoice: ( 486 | url: string, 487 | callback?: (status: InvoiceStatuses) => unknown 488 | ) => void; 489 | setHeaderColor: ( 490 | color: "bg_color" | "secondary_bg_color" | `#${string}` 491 | ) => void; 492 | setBackgroundColor: ( 493 | color: "bg_color" | "secondary_bg_color" | `#${string}` 494 | ) => void; 495 | showConfirm: ( 496 | message: string, 497 | callback?: (confirmed: boolean) => unknown 498 | ) => void; 499 | showPopup: (params: PopupParams, callback?: (id?: string) => unknown) => void; 500 | showAlert: (message: string, callback?: () => unknown) => void; 501 | enableClosingConfirmation: VoidFunction; 502 | disableClosingConfirmation: VoidFunction; 503 | showScanQrPopup: ( 504 | params: ScanQrPopupParams, 505 | callback?: (text: string) => void | true 506 | ) => void; 507 | closeScanQrPopup: () => void; 508 | readTextFromClipboard: (callback?: (text: string) => unknown) => void; 509 | ready: VoidFunction; 510 | switchInlineQuery: ( 511 | query: string, 512 | chooseChatTypes?: Array<"users" | "bots" | "groups" | "channels"> 513 | ) => void; 514 | requestWriteAccess: (callback?: (access: boolean) => unknown) => void; 515 | requestContact: ( 516 | callback?: (access: boolean, response?: RequestContactResponse) => unknown 517 | ) => void; 518 | BiometricManager: BiometricManager; 519 | isVerticalSwipesEnabled: boolean; 520 | enableVerticalSwipes: VoidFunction; 521 | disableVerticalSwipes: VoidFunction; 522 | shareToStory: (mediaURL: string, params?: ShareStoryParams) => void; 523 | bottomBarColor: string; 524 | setBottomBarColor: (bottomBarColor: string) => void; 525 | isActive: boolean; 526 | isFullscreen: boolean; 527 | isOrientationLocked: boolean; 528 | safeAreaInset: SafeAreaInset; 529 | contentSafeAreaInset: ContentSafeAreaInset; 530 | Accelerometer: Accelerometer; 531 | DeviceOrientation: DeviceOrientation; 532 | Gyroscope: Gyroscope; 533 | LocationManager: LocationManager; 534 | requestFullscreen: VoidFunction; 535 | exitFullscreen: VoidFunction; 536 | lockOrientation: VoidFunction; 537 | unlockOrientation: VoidFunction; 538 | addToHomeScreen: VoidFunction; 539 | checkHomeScreenStatus: ( 540 | callback?: (status: HomeScreenStatus) => unknown 541 | ) => void; 542 | shareMessage: ( 543 | msgId: string, 544 | callback?: (isSent: boolean) => unknown 545 | ) => void; 546 | setEmojiStatus: ( 547 | customEmojiId: string, 548 | params?: EmojiStatusParams, 549 | callback?: (isSet: boolean) => unknown 550 | ) => void; 551 | requestEmojiStatusAccess: ( 552 | callback?: (isGranted: boolean) => unknown 553 | ) => void; 554 | downloadFile: ( 555 | params: DownloadFileParams, 556 | callback?: (isAccepted: boolean) => unknown 557 | ) => void; 558 | } 559 | 560 | export interface Telegram { 561 | WebApp: WebApp; 562 | } 563 | --------------------------------------------------------------------------------