@telegram-apps/sdk
Version:
TypeScript Source Development Kit for Telegram Mini Apps client application.
59 lines (58 loc) • 2.62 kB
TypeScript
import { postEvent as _postEvent, PostEventFn, RequestFn, InvokeCustomMethodOptions, CustomMethodParams, CustomMethodName } from '@telegram-apps/bridge';
import { AbortablePromise } from 'better-promises';
import { LaunchParamsLike } from '@telegram-apps/transformers';
/**
* Launch parameters stored in the package state.
*/
export type PackageLaunchParams = Omit<LaunchParamsLike, 'tgWebAppThemeParams'> & Partial<Pick<LaunchParamsLike, 'tgWebAppThemeParams'>>;
export interface ConfigureOptions {
/**
* Launch parameters used across the package.
* @default Being extracted using the `retrieveLaunchParams` function.
* @see retrieveLaunchParams
*/
launchParams?: PackageLaunchParams;
/**
* Custom postEvent function.
* @default The `createPostEvent` function will be used with the version, specified in
* the `launchParams` option.
* @see createPostEvent
*/
postEvent?: PostEventFn;
}
export declare const $postEvent: import('@telegram-apps/signals').Signal<typeof _postEvent>;
export declare const _$launchParams: import('@telegram-apps/signals').Signal<PackageLaunchParams>, $launchParams: import('@telegram-apps/signals').Computed<PackageLaunchParams>;
export declare const version: import('@telegram-apps/signals').Computed<string>;
/**
* Configures package global dependencies.
* @param options - configuration additional options.
*/
export declare function configure(options?: ConfigureOptions): void;
/**
* @returns A new request identifier.
*/
export declare function createRequestId(): string;
/**
* Invokes known custom method. Returns method execution result.
* @param method - method name.
* @param params - method parameters.
* @param options - additional options.
* @throws {InvokeCustomMethodError} Invocation completed with some error.
*/
export declare function invokeCustomMethod<M extends CustomMethodName>(method: M, params: CustomMethodParams<M>, options?: InvokeCustomMethodOptions): AbortablePromise<unknown>;
/**
* Invokes unknown custom method. Returns method execution result.
* @param method - method name.
* @param params - method parameters.
* @param options - additional options.
* @throws {InvokeCustomMethodError} Invocation completed with some error.
*/
export declare function invokeCustomMethod(method: string, params: object, options?: InvokeCustomMethodOptions): AbortablePromise<unknown>;
/**
* `request` function from the bridge with applied global `postEvent` option.
*/
export declare const request: RequestFn;
/**
* Shortcut for $postEvent call.
*/
export declare const postEvent: PostEventFn;