@telegram-apps/sdk
Version:
TypeScript Source Development Kit for Telegram Mini Apps client application.
96 lines (95 loc) • 3.75 kB
TypeScript
import { AbortablePromise } from 'better-promises';
import { RequestOptionsNoCapture } from '../../../types.js';
interface OpenSharedOptions extends RequestOptionsNoCapture {
/**
* Title to be displayed in the scanner.
*/
text?: string;
}
/**
* Closes the scanner.
* @since Mini Apps v6.4
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @example
* if (close.isAvailable()) {
* close();
* }
*/
export declare const close: import('../../wrappers/wrapSafe.js').SafeWrapped<() => void, true, never>;
/**
* Signal indicating if the QR Scanner is currently opened.
*/
export declare const isSupported: import('@telegram-apps/signals').Computed<boolean>;
/**
* Opens the scanner and returns a promise which will be resolved with the QR content if the
* passed `capture` function returned true.
*
* The `capture` option may be ommited. In this case, the first scanned QR will be returned.
*
* Promise may also be resolved to undefined if the scanner was closed.
* @param options - method options.
* @returns A promise with QR content presented as string or undefined if the
* scanner was closed.
* @since Mini Apps v6.4
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @throws {ConcurrentCallError} The QR Scanner is already opened
* @example Without `capture` option
* if (captureOne.isAvailable()) {
* const qr = await captureOne({ text: 'Scan any QR' });
* }
* @example Using `capture` option
* if (captureOne.isAvailable()) {
* const qr = await captureOne({
* text: 'Scan any QR',
* capture(scannedQr) {
* return scannedQr === 'any expected by me qr';
* }
* });
* }
*/
declare function _open(options?: OpenSharedOptions & {
/**
* Function, which should return true if the scanned QR should be captured.
* @param qr - scanned QR content.
*/
capture?: (qr: string) => boolean;
}): AbortablePromise<string | undefined>;
/**
* Opens the scanner and calls the `onCaptured` function each time, a QR was scanned.
*
* The function returns a promise which will be resolved when the QR scanner was closed. It expects
* the scanner to be closed externally by a user or via the `close` method.
* @param options - method options.
* @since Mini Apps v6.4
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @throws {ConcurrentCallError} The QR Scanner is already opened
* @example
* if (captureMany.isAvailable()) {
* const promise = await captureMany({
* text: 'Scan any QR',
* onCaptured(scannedQr) {
* if (scannedQr === 'any expected by me qr') {
* close();
* }
* }
* });
* console.log('The scanner was closed');
* }
*/
declare function _open(options: OpenSharedOptions & {
/**
* Function which will be called if a QR code was scanned.
* @param qr - scanned QR content.
*/
onCaptured: (qr: string) => void;
}): AbortablePromise<void>;
export declare const open: import('../../wrappers/wrapSafe.js').SafeWrapped<typeof _open, true, never>;
export declare const openPromise: import('@telegram-apps/signals').Computed<AbortablePromise<void> | undefined>, isOpened: import('@telegram-apps/signals').Computed<boolean>;
export declare const openError: import('@telegram-apps/signals').Computed<Error | undefined>;
export {};