// Types of the Toki Web App SDK v1 (https://toki.biz/assets/toki-webapp-v1.js). export type TokiColorScheme = 'light' | 'dark'; export type TokiPlatform = 'ios' | 'android' | 'web' | 'unknown'; export interface TokiSafeArea { top: number; right: number; bottom: number; left: number } /** Toki's colours for the current scheme. The same values are set as CSS variables `--toki-bg`, `--toki-card`, `--toki-text`, `--toki-text-secondary`, `--toki-accent`, `--toki-on-accent`, `--toki-hairline`. */ export interface TokiTheme { bg: string; card: string; text: string; textSecondary: string; accent: string; onAccent: string; hairline: string; } export interface TokiMainButton { readonly isVisible: boolean; readonly isEnabled: boolean; readonly text: string; /** Up to 32 characters. */ setText(text: string): TokiMainButton; show(): TokiMainButton; hide(): TokiMainButton; enable(): TokiMainButton; disable(): TokiMainButton; showProgress(): TokiMainButton; hideProgress(): TokiMainButton; onClick(callback: () => void): TokiMainButton; offClick(callback: () => void): TokiMainButton; } export interface TokiBackButton { readonly isVisible: boolean; show(): TokiBackButton; hide(): TokiBackButton; onClick(callback: () => void): TokiBackButton; offClick(callback: () => void): TokiBackButton; } export interface TokiHapticFeedback { impact(style?: 'light' | 'medium' | 'heavy'): void; notification(kind?: 'success' | 'warning' | 'error'): void; selection(): void; } export interface TokiEvents { themeChanged: { colorScheme: TokiColorScheme }; viewportChanged: { safeArea: TokiSafeArea }; visibilityChanged: { isVisible: boolean }; mainButtonClicked: undefined; backButtonClicked: undefined; } export type TokiBridgeMessage = | 'ready' | 'close' | 'minimize' | 'open_link' | 'closing_confirmation' | 'main_button' | 'back_button' | 'haptic'; export interface TokiWebApp { readonly version: 1; /** One-time launch data. Send it to your server unchanged; the server exchanges it at `POST /api/bot/v1/webapp/session`. Empty outside Toki. */ readonly initData: string; /** For drawing before sign-in only. The trusted copy comes with the session answer. */ readonly startParam: string; readonly platform: TokiPlatform; readonly lang: 'ru' | 'en'; readonly colorScheme: TokiColorScheme; readonly theme: TokiTheme; readonly safeArea: TokiSafeArea; readonly isVisible: boolean; supports(name: TokiBridgeMessage | (string & {})): boolean; /** The first screen is drawn: Toki removes its loader. */ ready(): void; close(): void; minimize(): void; /** Toki asks the person before leaving. */ openLink(url: string): void; setClosingConfirmation(enabled: boolean): void; readonly MainButton: TokiMainButton; readonly BackButton: TokiBackButton; readonly HapticFeedback: TokiHapticFeedback; onEvent(name: K, callback: (data: TokiEvents[K]) => void): void; offEvent(name: K, callback: (data: TokiEvents[K]) => void): void; } declare global { interface Window { Toki: { readonly WebApp: TokiWebApp } } const Toki: { readonly WebApp: TokiWebApp }; }