• Simple wrapper that calls start and then provided callback function (if any) without the need to introduce a main() function manually.

    Errors that were encountered while calling start and then will be emitted as usual, and can be caught with onError

    Parameters

    • client: ITelegramClient
    • params: {
          abortSignal?: AbortSignal;
          botToken?: MaybeDynamic<string>;
          code?: MaybeDynamic<string>;
          codeSentCallback?: ((code: SentCode) => MaybePromise<void>);
          codeSettings?: Omit<RawCodeSettings, "_" | "logoutTokens">;
          forceSms?: boolean;
          futureAuthTokens?: Uint8Array[];
          invalidCodeCallback?: ((type: "code" | "password") => MaybePromise<void>);
          password?: MaybeDynamic<string>;
          phone?: MaybeDynamic<string>;
          qrCodeHandler?: ((url: string, expires: Date) => void);
          session?: string | StringSessionData;
          sessionForce?: boolean;
      }

      Parameters to be passed to start

      • OptionalabortSignal?: AbortSignal

        Abort signal

      • OptionalbotToken?: MaybeDynamic<string>

        Bot token to use. Ignored if phone is supplied.

      • Optionalcode?: MaybeDynamic<string>

        Code sent to the phone (either sms, call, flash call or other). Ignored if botToken is supplied, must be present if phone is supplied.

      • OptionalcodeSentCallback?: ((code: SentCode) => MaybePromise<void>)

        Custom method that is called when a code is sent. Can be used to show a GUI alert of some kind.

        This method is called before start.params.code.

        console.log.

      • OptionalcodeSettings?: Omit<RawCodeSettings, "_" | "logoutTokens">

        Additional code settings to pass to the server

      • OptionalforceSms?: boolean

        Whether to force code delivery through SMS

      • OptionalfutureAuthTokens?: Uint8Array[]

        Saved future auth tokens, if any

      • OptionalinvalidCodeCallback?: ((type: "code" | "password") => MaybePromise<void>)

        If passed, this function will be called if provided code or 2FA password was invalid. New code/password will be requested later.

        If provided code/password is a constant string, providing an invalid one will interrupt authorization flow.

      • Optionalpassword?: MaybeDynamic<string>

        2FA password. Ignored if botToken is supplied

      • Optionalphone?: MaybeDynamic<string>

        Phone number of the account. If account does not exist, it will be created

      • OptionalqrCodeHandler?: ((url: string, expires: Date) => void)

        When passed, QR login flow will be used instead of the regular login flow.

        This function will be called whenever the login URL is changed, and the app is expected to display it as a QR code to the user.

          • (url, expires): void
          • Parameters

            • url: string
            • expires: Date

            Returns void

      • Optionalsession?: string | StringSessionData

        String session exported using TelegramClient.exportSession.

        This simply calls TelegramClient.importSession before anything else.

        Note that passed session will be ignored in case storage already contains authorization.

      • OptionalsessionForce?: boolean

        Whether to overwrite existing session.

    • Optionalthen: ((user: User) => void | Promise<void>)

      Function to be called after start returns

        • (user): void | Promise<void>
        • Parameters

          Returns void | Promise<void>

    Returns void

    This method provides no real value over start, please use it instead