import { Api } from "../tl";
import type { TelegramClient } from "./TelegramClient";
/**
* For when you want to login as a {@link Api.User}
* this should handle all needed steps for authorization as a user.
* to stop the operation at any point just raise and error with the message `AUTH_USER_CANCEL`.
*/
export interface UserAuthParams {
/** Either a string or a callback that returns a string for the phone to use to login. */
phoneNumber: string | (() => Promise);
/** callback that should return the login code that telegram sent.
* has optional bool `isCodeViaApp` param for whether the code was sent through the app (true) or an SMS (false). */
phoneCode: (isCodeViaApp?: boolean) => Promise;
/** optional string or callback that should return the 2FA password if present.
* the password hint will be sent in the hint param */
password?: (hint?: string) => Promise;
/** in case of a new account creation this callback should return a first name and last name `[first,last]`. */
firstAndLastNames?: () => Promise<[string, string?]>;
/** a qrCode token for login through qrCode.
* this would need a QR code that you should scan with another app to login with. */
qrCode?: (qrCode: {
token: Buffer;
expires: number;
}) => Promise;
/** when an error happens during auth this function will be called with the error.
* if this returns true the auth operation will stop. */
onError: (err: Error) => Promise | void;
/** whether to send the code through SMS or not. */
forceSMS?: boolean;
}
export interface UserPasswordAuthParams {
/** optional string or callback that should return the 2FA password if present.
* the password hint will be sent in the hint param */
password?: (hint?: string) => Promise;
/** when an error happens during auth this function will be called with the error.
* if this returns true the auth operation will stop. */
onError: (err: Error) => Promise | void;
}
export interface QrCodeAuthParams extends UserPasswordAuthParams {
/** a qrCode token for login through qrCode.
* this would need a QR code that you should scan with another app to login with. */
qrCode?: (qrCode: {
token: Buffer;
expires: number;
}) => Promise;
/** when an error happens during auth this function will be called with the error.
* if this returns true the auth operation will stop. */
onError: (err: Error) => Promise | void;
}
interface ReturnString {
(): string;
}
/**
* For when you want as a normal bot created by https://t.me/Botfather.
* Logging in as bot is simple and requires no callbacks
*/
export interface BotAuthParams {
/**
* the bot token to use.
*/
botAuthToken: string | ReturnString;
}
/**
* Credential needed for the authentication. you can get theses from https://my.telegram.org/auth
* Note: This is required for both logging in as a bot and a user.
*/
export interface ApiCredentials {
/** The app api id. */
apiId: number;
/** the app api hash */
apiHash: string;
}
/** @hidden */
export declare function start(client: TelegramClient, authParams: UserAuthParams | BotAuthParams): Promise;
/** @hidden */
export declare function checkAuthorization(client: TelegramClient): Promise;
/** @hidden */
export declare function signInUser(client: TelegramClient, apiCredentials: ApiCredentials, authParams: UserAuthParams): Promise;
/** @hidden */
export declare function signInUserWithQrCode(client: TelegramClient, apiCredentials: ApiCredentials, authParams: QrCodeAuthParams): Promise;
/** @hidden */
export declare function sendCode(client: TelegramClient, apiCredentials: ApiCredentials, phoneNumber: string, forceSMS?: boolean): Promise<{
phoneCodeHash: string;
isCodeViaApp: boolean;
}>;
/** @hidden */
export declare function signInWithPassword(client: TelegramClient, apiCredentials: ApiCredentials, authParams: UserPasswordAuthParams): Promise;
/** @hidden */
export declare function signInBot(client: TelegramClient, apiCredentials: ApiCredentials, authParams: BotAuthParams): Promise;
/** @hidden */
export declare function _authFlow(client: TelegramClient, apiCredentials: ApiCredentials, authParams: UserAuthParams | BotAuthParams): Promise;
export {};