add eitaa-mini-app skill
This commit is contained in:
6 files changed
+402
No files matched your search
@@ -0,0 +1,131 @@
|
||||
# Eitaa WebApp SDK reference
|
||||
|
||||
This is a compact implementation reference distilled from the supplied Eitaa documentation. Feature-detect at runtime because client versions differ.
|
||||
|
||||
## Loading and adapter
|
||||
|
||||
Place this before application scripts:
|
||||
|
||||
```html
|
||||
<script src="https://developer.eitaa.com/eitaa-web-app.js"></script>
|
||||
```
|
||||
|
||||
Do not self-host the SDK. A small project-local adapter is useful for SSR safety and compatibility:
|
||||
|
||||
```js
|
||||
export function getEitaaWebApp() {
|
||||
return typeof window === "undefined" ? undefined : window.Eitaa?.WebApp;
|
||||
}
|
||||
|
||||
export function callFullscreen(webApp, enter) {
|
||||
const method = enter
|
||||
? webApp?.requestFullscreen ?? webApp?.requestFullScreen
|
||||
: webApp?.exitFullscreen ?? webApp?.exitFullScreen;
|
||||
return typeof method === "function" ? method.call(webApp) : undefined;
|
||||
}
|
||||
```
|
||||
|
||||
The documentation spells fullscreen as `requestFullScreen` / `exitFullScreen`; current clients may expose `requestFullscreen` / `exitFullscreen`. Do not assume either spelling without detection.
|
||||
|
||||
## Initialization pattern
|
||||
|
||||
1. Resolve the bridge after client mount.
|
||||
2. Establish event handlers with stable references.
|
||||
3. Synchronize the theme and safe-area-aware layout.
|
||||
4. Render the essential UI.
|
||||
5. Call `ready()` once.
|
||||
6. Call `expand()` or other lifecycle methods only if desired.
|
||||
7. On cleanup, unregister events and stop active sensors.
|
||||
|
||||
Presence of `window.Eitaa` alone is weak environment detection. For native-only actions also require `WebApp`, expected methods, and normally non-empty `initData`; still handle every call as potentially unsupported.
|
||||
|
||||
## Core fields
|
||||
|
||||
- Launch and environment: `initData`, `initDataUnsafe`, `version`, `platform`, `isVersionAtLeast(version)`.
|
||||
- Appearance: `colorScheme`, `themeParams`, `headerColor`, `backgroundColor`, `bottomBarColor`.
|
||||
- Viewport: `isExpanded`, `isActive`, `isFullscreen`, `isOrientationLocked`, `viewportHeight`, `viewportStableHeight`, `safeAreaInset`, `contentSafeAreaInset`.
|
||||
- Lifecycle state: `isClosingConfirmationEnabled`, `isVerticalSwipesEnabled`.
|
||||
- Native controls: `MainButton`, `SecondaryButton`, `BackButton`, `SettingsButton`, `HapticFeedback`.
|
||||
- Sensors: `Accelerometer`, `DeviceOrientation`, `Gyroscope`.
|
||||
|
||||
`initDataUnsafe` can contain `query_id`, `user`, `chat_type`, `chat_instance`, `start_param`, `auth_date`, `device_id`, and `hash`. `chat_type`, `chat_instance`, and `start_param` are documented as mini-app/direct-link fields. Never authenticate from this parsed object.
|
||||
|
||||
User fields are `id`, `first_name`, optional `last_name`, optional `language_code`, and optional `allows_write_to_pm`. IDs may use up to 52 significant bits; preserve them safely in the server language and avoid 32-bit storage.
|
||||
|
||||
## Methods by capability
|
||||
|
||||
Lifecycle and viewport:
|
||||
|
||||
- `ready()`, `expand()`, `close()`
|
||||
- `enableClosingConfirmation()`, `disableClosingConfirmation()`
|
||||
- `enableVerticalSwipes()`, `disableVerticalSwipes()`
|
||||
- `requestFullScreen()` / `exitFullScreen()` with compatibility aliases above
|
||||
- `lockOrientation()`, `unlockOrientation()`
|
||||
- `addToHomeScreen()`, `checkHomeScreenStatus()`
|
||||
|
||||
Appearance and native UI:
|
||||
|
||||
- `setHeaderColor(color)`, `setBackgroundColor(color)`, `setBottomBarColor(color)`
|
||||
- `showAlert(message, callback)`, `showConfirm(message, callback)`
|
||||
- `showPopup(params, callback)`
|
||||
- `MainButton` and `SecondaryButton`: `setText`, `setParams`, `show`, `hide`, `enable`, `disable`, `showProgress`, `hideProgress`, `onClick`, `offClick`
|
||||
- `BackButton` and `SettingsButton`: `show`, `hide`, `onClick`, `offClick`
|
||||
- `HapticFeedback.impactOccurred(style)`, `notificationOccurred(type)`, `selectionChanged()`
|
||||
|
||||
Links, permissions, and content:
|
||||
|
||||
- `openLink(url, {try_instant_view?, try_browser?})`; call only from a user interaction.
|
||||
- `openEitaaLink(url)` for an Eitaa link inside Eitaa.
|
||||
- `requestWriteAccess(callback)` and `requestContact(callback)`.
|
||||
- `showScanQrPopup({text?}, callback)` and `closeScanQrPopup()`.
|
||||
- `downloadFile({url, file_name})`; the URL must be HTTPS.
|
||||
|
||||
Sensors:
|
||||
|
||||
- `Accelerometer.start({refresh_rate}, callback)` and `.stop(callback)` expose `isStarted`, `x`, `y`, `z` in m/s².
|
||||
- `Gyroscope.start({refresh_rate}, callback)` and `.stop(callback)` expose `isStarted`, `x`, `y`, `z` in rad/s.
|
||||
- `DeviceOrientation.start({refresh_rate, need_absolute}, callback)` and `.stop(callback)` expose `isStarted`, `absolute`, `alpha`, `beta`, `gamma` in radians.
|
||||
- Documented `refresh_rate` range is 20–1000 ms and the platform may choose a different actual rate.
|
||||
|
||||
Always stop sensors when no longer visible or mounted.
|
||||
|
||||
## Native button and popup parameters
|
||||
|
||||
`BottomButton.setParams` accepts documented snake_case fields: `text`, `color`, `text_color`, `is_active`, `is_visible`, `position`, and `has_shine_effect`. Secondary positions are `left`, `right`, `top`, or `bottom`. Keep a stable callback reference for `onClick`/`offClick`.
|
||||
|
||||
`showPopup` accepts a title of at most 64 characters, a required message of 1–256 characters, and one to three buttons. Button `id` and custom `text` are at most 64 characters. Types are `default`, `ok`, `close`, `cancel`, and `destructive`; custom text is required for `default` and `destructive`.
|
||||
|
||||
## Theme and layout
|
||||
|
||||
Use the CSS variables supplied by the client, with fallbacks:
|
||||
|
||||
- `--tg-color-scheme`
|
||||
- `--tg-theme-bg-color`, `--tg-theme-text-color`, `--tg-theme-hint-color`, `--tg-theme-link-color`
|
||||
- `--tg-theme-button-color`, `--tg-theme-button-text-color`, `--tg-theme-secondary-bg-color`
|
||||
- `--tg-theme-header-bg-color`, `--tg-theme-bottom-bar-bg-color`
|
||||
- `--tg-theme-accent-text-color`, `--tg-theme-section-bg-color`, `--tg-theme-section-header-text-color`
|
||||
- `--tg-theme-section-separator-color`, `--tg-theme-subtitle-text-color`, `--tg-theme-destructive-text-color`
|
||||
- `--tg-safe-area-inset-{top,right,bottom,left}`
|
||||
- `--tg-content-safe-area-inset-{top,right,bottom,left}`
|
||||
- `--tg-viewport-height`, `--tg-viewport-stable-height`
|
||||
|
||||
Use stable height for UI pinned to the bottom. Live `viewportHeight` is not updated smoothly enough for that purpose.
|
||||
|
||||
## Events
|
||||
|
||||
Subscribe through `onEvent(name, handler)` and remove through `offEvent(name, handler)`:
|
||||
|
||||
- Environment/layout: `themeChanged`, `viewportChanged`, `activated`, `deactivated`, `safeAreaChanged`, `contentSafeAreaChanged`.
|
||||
- Controls/dialogs: `mainButtonClicked`, `backButtonClicked`, `settingsButtonClicked`, `popupClosed`.
|
||||
- QR/permissions: `qrTextReceived`, `scanQrPopupClosed`, `writeAccessRequested`, `contactRequested`.
|
||||
- Fullscreen/home screen: `fullscreenChanged`, `fullscreenFailed`, `homeScreenAdded`, `homeScreenChecked`.
|
||||
|
||||
`viewportChanged` provides `isStateStable`. Permission events return statuses such as `allowed`/`cancelled` or `sent`/`cancelled`. Fullscreen failure includes an error. Home-screen check returns a status such as `unsupported`, `unknown`, `added`, or `missed`.
|
||||
|
||||
Treat event payloads as input, redact sensitive fields from telemetry, and never open QR content automatically.
|
||||
|
||||
## Version notes from the documentation snapshot
|
||||
|
||||
SDK 1.3 marks orientation lock state, bottom bar color, secondary button, safe areas, sensors, bottom-bar color setter, home-screen methods, orientation methods, fullscreen, and `try_browser`. `downloadFile` is marked SDK 1.4. Guard these with feature detection even when the version claims support.
|
||||
|
||||
Do not implement the documentation's commented placeholders for stories, emoji status, cloud storage, biometrics, location, device storage, secure storage, or chat objects without newer authoritative documentation.
|
||||
Reference in new issue
Block a user