### Runtime Specific Imports Source: https://ref.mtcute.dev/media/modules.html Package installation and import examples for Bun and Deno runtimes. ```bash bun add @mtcute/bun ``` ```typescript import { TelegramClient } from 'jsr:@mtcute/deno' ``` -------------------------------- ### Install @mtcute/postgres Source: https://ref.mtcute.dev/modules/_mtcute_postgres.html Install the package and the required pg driver. ```bash pnpm add @mtcute/postgres pg ``` -------------------------------- ### Optional setup Method Source: https://ref.mtcute.dev/interfaces/_mtcute_core.index.IStorageDriver.html The optional setup method initializes the driver with a logger instance and platform object. This is useful for drivers that require logging or platform-specific functionalities. ```typescript setup?: (log: Logger, platform: ICorePlatform) => void ``` -------------------------------- ### Function start Source: https://ref.mtcute.dev/funcs/_mtcute_bun.methods.start.html Starts the client in an interactive and declarative manner, handling login, sign up, and 2FA processes. ```APIDOC ## start(client, params) ### Description Starts the client in an interactive and declarative manner, by providing callbacks for authorization details. This method handles both login and sign up, and also handles 2FA. ### Parameters - **client** (ITelegramClient) - Required - The Telegram client instance. - **params** (Object) - Required - Configuration parameters for the authorization flow. #### params Object - **abortSignal** (AbortSignal) - Optional - Abort signal. - **botToken** (MaybeDynamic) - Optional - Bot token to use. Ignored if phone is supplied. - **code** (MaybeDynamic) - Optional - Code sent to the phone. Ignored if botToken is supplied. - **codeSentCallback** (Function) - Optional - Custom method called when a code is sent. - **codeSettings** (Object) - Optional - Additional code settings to pass to the server. - **forceSms** (boolean) - Optional - Whether to force code delivery through SMS. - **futureAuthTokens** (Uint8Array[]) - Optional - Saved future auth tokens. - **invalidCodeCallback** (Function) - Optional - Called if provided code or 2FA password was invalid. - **password** (MaybeDynamic) - Optional - 2FA password. Ignored if botToken is supplied. - **phone** (MaybeDynamic) - Optional - Phone number of the account. - **qrCodeHandler** (Function) - Optional - Enables QR login flow when provided. - **session** (string | InputStringSessionData) - Optional - String session exported using TelegramClient.exportSession. - **sessionForce** (boolean) - Optional - Whether to overwrite existing session. ### Returns - **Promise** - Returns a promise that resolves to the authenticated User object. ``` -------------------------------- ### Installation Source: https://ref.mtcute.dev/modules/_mtcute_postgres.html Install the @mtcute/postgres module and the pg package using pnpm. ```APIDOC ## Installation ``` pnpm add @mtcute/postgres pg ``` ``` -------------------------------- ### Function start Source: https://ref.mtcute.dev/funcs/_mtcute_node.methods.start.html Starts the client in an interactive and declarative manner, handling authorization details through provided callbacks. This method supports both login and sign-up flows, including two-factor authentication. ```APIDOC ## Function start ### Description Start the client in an interactive and declarative manner, by providing callbacks for authorization details. This method handles both login and sign up, and also handles 2FV. All parameters are `MaybeDynamic`, meaning you can either supply `T`, or a function that returns `MaybePromise`. This method is intended for _interactive_ login. If you are building some kind of headless service, you will most likely want to use the underlying authorization methods directly. ### Method POST ### Endpoint /start ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **client** (ITelegramClient) - Required - The Telegram client instance. - **params** (object) - Optional - Parameters for starting the client. - **abortSignal** (AbortSignal) - Optional - Abort signal. - **botToken** (MaybeDynamic) - Optional - Bot token to use. Ignored if `phone` is supplied. - **code** (MaybeDynamic) - Optional - Code sent to the phone. Ignored if `botToken` is supplied, must be present if `phone` is supplied. - **codeSentCallback** ((code: SentCode) => MaybePromise) - Optional - Custom method called when a code is sent. Called before `start.params.code`. Default: `console.log`. - **codeSettings** (Omit) - Optional - Additional code settings to pass to the server. - **forceSms** (boolean) - Optional - Whether to force code delivery through SMS. - **futureAuthTokens** (Uint8Array[]) - Optional - Saved future auth tokens, if any. - **invalidCodeCallback** ((type: "code" | "password") => MaybePromise) - Optional - Called if the provided code or 2FA password was invalid. New code/password will be requested later. - **password** (MaybeDynamic) - Optional - 2FA password. Ignored if `botToken` is supplied. - **phone** (MaybeDynamic) - Optional - Phone number of the account. If account does not exist, it will be created. - **qrCodeHandler** ((url: string, expires: Date) => void) - Optional - 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. - **session** (string | InputStringSessionData) - Optional - 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. - **sessionForce** (boolean) - Optional - Whether to overwrite existing session. ### Request Example ```json { "client": "", "params": { "phone": "+1234567890", "codeSentCallback": "(code) => console.log('Code sent:', code)", "password": "my2FApassword" } } ``` ### Response #### Success Response (200) - **User** (User) - Information about the logged-in user. #### Response Example ```json { "id": 123456789, "firstName": "John", "lastName": "Doe", "username": "johndoe" } ``` ``` -------------------------------- ### startUpdatesLoop Source: https://ref.mtcute.dev/classes/_mtcute_deno.index.BaseTelegramClient.html Starts the loop for receiving updates from the server. ```APIDOC ## startUpdatesLoop ### Description Start the updates loop. ### Method POST ### Endpoint /updates/start_loop ### Returns Promise ``` -------------------------------- ### Optional setup Method Signature Source: https://ref.mtcute.dev/interfaces/_mtcute_bun.index.TelegramTransport.html The optional setup method allows for initializing the transport with crypto and logging capabilities. It takes ICryptoProvider and Logger as parameters and returns void. ```typescript setup?(crypto: ICryptoProvider, log: Logger): void ``` -------------------------------- ### Deno Import Example Source: https://ref.mtcute.dev/media/crypto Importing the Telegram client in a Deno environment. ```typescript import { TelegramClient } from 'jsr:@mtcute/deno' ``` -------------------------------- ### Installation Commands Source: https://ref.mtcute.dev/media/crypto Commands to initialize a new project or add mtcute packages to existing environments. ```bash pnpm create @mtcute/bot ``` ```bash pnpm add @mtcute/node ``` ```bash pnpm add @mtcute/web ``` ```bash bun add @mtcute/bun ``` -------------------------------- ### startLoop Source: https://ref.mtcute.dev/classes/_mtcute_core.index.UpdatesManager.html Starts the background updates processing loop. ```APIDOC ## startLoop ### Description Start updates loop. You must first call enableUpdatesProcessing to use this method. ### Returns - **Promise** ``` -------------------------------- ### startLoop Source: https://ref.mtcute.dev/classes/_mtcute_web.index.UpdatesManager.html Starts the updates processing loop. ```APIDOC ## startLoop ### Description Start updates loop. You must first call enableUpdatesProcessing to use this method. ### Response - **Returns** (Promise) ``` -------------------------------- ### Basic Usage Source: https://ref.mtcute.dev/modules/_mtcute_postgres.html Example of how to use PostgresStorage with a TelegramClient. ```APIDOC ## Usage ```typescript import { TelegramClient } from '@mtcute/node' import { PostgresStorage } from '@mtcute/postgres' import pg from 'pg' const pool = new pg.Pool({ connectionString: 'postgres://localhost/mydb' }) const tg = new TelegramClient({ apiId: 12345, apiHash: 'abcdef', storage: new PostgresStorage(pool), }) const self = await tg.start() console.log(`logged in as ${self.displayName}`) ``` ``` -------------------------------- ### Start Updates Loop Source: https://ref.mtcute.dev/classes/_mtcute_bun.index.BaseTelegramClient.html Starts the loop for receiving and processing updates from the server. ```APIDOC ## POST /updates/start_loop ### Description Start the updates loop. ### Method POST ### Endpoint /updates/start_loop ### Response #### Success Response (200) - **status** (string) - Indicates that the updates loop has started. #### Response Example ```json { "status": "started" } ``` ``` -------------------------------- ### get Method Source: https://ref.mtcute.dev/classes/_mtcute_core.index.MemoryAuthKeysRepository.html Retrieves the authentication key for a specific data center. ```APIDOC ## get ### Description Get auth_key for the given DC. ### Method GET ### Endpoint /api/authkeys/dc/{dc} ### Parameters #### Path Parameters - **dc** (number) - Required - The data center ID. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Uint8Array | null** - The authentication key for the specified DC, or null if not found. #### Response Example ```json { "key": "base64EncodedKey" } ``` ``` -------------------------------- ### Initialize TelegramClient with PostgresStorage Source: https://ref.mtcute.dev/modules/_mtcute_postgres.html Basic setup for using PostgreSQL as the storage backend for a Telegram client. ```typescript import { TelegramClient } from '@mtcute/node' import { PostgresStorage } from '@mtcute/postgres' import pg from 'pg' const pool = new pg.Pool({ connectionString: 'postgres://localhost/mydb' }) const tg = new TelegramClient({ apiId: 12345, apiHash: 'abcdef', storage: new PostgresStorage(pool), }) const self = await tg.start() console.log(`logged in as ${self.displayName}`) ``` -------------------------------- ### Get Video Start Timestamp Source: https://ref.mtcute.dev/classes/_mtcute_web.index.Video.html Returns the video start timestamp in seconds, or null if not available. ```typescript get videoStartTs(): number | null ``` -------------------------------- ### Prepare Client Source: https://ref.mtcute.dev/interfaces/_mtcute_web.index.ITelegramClient.html The `prepare` method performs necessary initializations for the client before it can be used. This might include setting up storage or other internal components. ```typescript prepare(): Promise ``` -------------------------------- ### Example: Predicate Source: https://ref.mtcute.dev/interfaces/_mtcute_tl-utils.index.TlTypeModifiers.html Provides an example of a predicate, which is used to specify conditions or flags for an argument. ```typescript `flags.3` ``` -------------------------------- ### Date-time Entity Examples - @mtcute/html-parser Source: https://ref.mtcute.dev/modules/_mtcute_html-parser Examples of using `` and `