import { ColorScheme, SettableColorKey, Version } from './types'; import { Bridge } from '../Bridge'; import { RGBColor } from 'twa-core'; import { WebAppEventsMap } from './events'; /** * Provides functionality which is recognized as common for Web Apps. In other * words, this class mostly contains utilities. */ export declare class WebApp { private bridge; private ee; private _backgroundColor; private _headerColor; private _isClosingConfirmationEnabled; /** * Updates current closing confirmation enable status. * * @param value - new closing confirmation status. * @private */ private set isClosingConfirmationEnabled(value); constructor(bridge: Bridge, headerColor: SettableColorKey, backgroundColor: RGBColor, version: Version, isClosingConfirmationEnabled?: boolean); /** * Current native application background color. */ get backgroundColor(): RGBColor; /** * Closes the Web App. */ close: () => void; /** * Returns current application color scheme. This value is computed according * to current background color. */ get colorScheme(): ColorScheme; /** * Disables the confirmation dialog while the user is trying to close the * Web App. */ disableClosingConfirmation: () => void; /** * Enables the confirmation dialog while the user is trying to close the * Web App. */ enableClosingConfirmation: () => void; /** * Current native application header color key. */ get headerColor(): SettableColorKey; /** * `true`, if the confirmation dialog enabled while the user is trying to * close the Web App. */ get isClosingConfirmationEnabled(): boolean; /** * Return `true` in case, passed version is more than or equal to current * Web App version. * * @param version - compared version. */ isVersionAtLeast: (version: Version) => boolean; /** * Opens a link in an external browser. The Web App will not be closed. * * Note that this method can be called only in response to the user * interaction with the Web App interface (e.g. click inside the Web App * or on the main button). * * @param url - URL to be opened. */ openLink: (url: string) => void; /** * Opens a telegram link inside Telegram app. The Web App will be closed. * * @param url - URL to be opened. * @throws {Error} URL has not allowed hostname. * @since Web App version 6.1+ */ openTelegramLink: (url: string) => void; /** * TODO: Check docs. * FIXME: Implement * Opens an invoice using the link url. * * @since Bot API 6.1+ * @param url */ openInvoice: (url: string) => void; /** * Adds new event listener. */ on: (event: E, listener: import("twa-core").EventListener) => void; /** * Removes event listener. */ off: (event: E, listener: import("twa-core").EventListener) => void; /** * Informs the Telegram app that the Web App is ready to be displayed. * * It is recommended to call this method as early as possible, as soon as * all essential interface elements loaded. Once this method called, * the loading placeholder is hidden and the Web App shown. * * If the method not called, the placeholder will be hidden only when * the page fully loaded. */ ready: () => void; /** * Checks if current version satisfies minimum (passed) version. * * @param version - version number. * @throws {Error} Version of Web App does not support this method. */ requireVersion: (version: Version) => void; /** * A method used to send data to the bot. When this method called, a * service message sent to the bot containing the data of the * length up to 4096 bytes, and the Web App closed. See the field * `web_app_data` in the class Message. * * This method is only available for Web Apps launched via a Keyboard button. * * @param data - data to send to bot. * @throws {Error} data has incorrect size. */ sendData: (data: string) => void; /** * Updates current application background color. * FIXME: Has no effect on desktop, works incorrectly on Android. * Issues: * https://github.com/Telegram-Web-Apps/client-sdk/issues/1 * https://github.com/Telegram-Web-Apps/client-sdk/issues/2 * * @param color - settable color key or color description in known RGB * format. * @since Web App version 6.1+ */ setBackgroundColor: (color: RGBColor) => void; /** * Updates current application header color. * FIXME: Has no effect on desktop, works incorrectly on Android. * Issues: * https://github.com/Telegram-Web-Apps/client-sdk/issues/1 * https://github.com/Telegram-Web-Apps/client-sdk/issues/2 * * @param color - settable color key. * @since Web App version 6.1+ */ setHeaderColor: (color: SettableColorKey) => void; /** * Current Web App version. This property is used by other components to check if * some functionality is available on current device. */ version: Version; }