// AUTOGENERATED, edit index.js.flow instead
import {
Update as Td$Update,
error as Td$error,
Invoke,
Execute,
setTdlibParameters as Td$setTdlibParameters
} from 'tdlib-types'
export type TDLibParameters = Omit
export type TDLibConfiguration = {
/**
* The path to libtdjson. Defaults to `'tdjson.dll'` on Windows,
* `'libtdjson.dylib'` on macOS, or `'libtdjson.so'` on a different OS.
*/
tdjson?: string,
/**
* The path to the directory with libtdjson. Defaults to `''`. Can be set to,
* for example, `'/usr/local/lib'` or `__dirname` while keeping the `tdjson`
* option unchanged.
*/
libdir?: string,
/**
* Set the verbosity level of TDLib. From the TDLib documentation: "value 0
* corresponds to fatal errors, value 1 corresponds to errors, value 2
* corresponds to warnings and debug warnings, value 3 corresponds to
* informational, value 4 corresponds to debug, value 5 corresponds to verbose
* debug, value greater than 5 and up to 1024 can be used to enable even more
* logging". Another possible option is `'default'`, `tdl` will then not send
* any verbosity level to TDLib. Defaults to 2.
*/
verbosityLevel?: number | 'default',
/**
* Experimental option. Use the new tdjson interface (`td_create_client_id`
* and other functions) that was added in TDLib v1.7.0. */
useNewTdjsonInterface?: boolean,
/**
* Advanced option. Configures the delay for the `receive` tdjson function.
* Defaults to `10.0` seconds.
*/
receiveTimeout?: number
}
/**
* Configure options such as path to the tdjson library or the verbosity level.
* Only options passed in the object are set; can be called none or multiple
* times. The shared library will be loaded using `path.join(libdir, tdjson)` as
* `filename`. Should be called before `createClient` / `execute` / `init`.
*/
export function configure(cfg: TDLibConfiguration): void;
/** Create a TDLib client. */
export function createClient(opts: ClientOptions): Client;
/**
* Call a TDLib method synchronously. Can be used only with the methods
* marked as "can be called synchronously" in the TDLib documentation.
*/
export var execute: Execute;
/**
* Initialize the node addon explicitly. This function is entirely optional to
* call, TDLib will be initialized automatically on the first call of
* `createClient`, `execute`, or `setLogMessageCallback`.
*/
export function init(): void;
/**
* The `td_set_log_message_callback` tdjson function, sets the callback that
* will be called when a message is added to the internal TDLib log. Note that
* setting a callback overrides the previous callback. Pass null to remove the
* callback. Available since TDLib v1.8.0.
*/
export var setLogMessageCallback: (
maxVerbosityLevel: number,
callback: null | ((verbosityLevel: number, message: string) => void)
) => void;
export class Client {
/**
* Log in to a Telegram account. `getLoginDetails` will not be called if the
* client is already logged in.
*/
login: (getLoginDetails?: () => LoginDetails) => Promise;
/**
* Log in as a bot. You can get the token from `@BotFather`.
* If the client is already logged in as a user, it will not be relogged
* as a bot. In case a function is passed instead of string, it will not be
* called if you are already logged in.
* This function is short for
* ```
* client.login(() => ({
* type: 'bot',
* getToken: retry => retry
* ? Promise.reject('Invalid bot token')
* : Promise.resolve(typeof token === 'string' ? token : token())
* }))
* ```
*/
loginAsBot: (token: string | (() => string | Promise)) => Promise;
/** Attach an event listener. Use this function to iterate through updates. */
on: On;
/** Attach a one-time event listener. */
once: On;
/** Remove an event listener. */
off: Off;
/** Alias for `client.on`. */
addListener: On;
/** Alias for `client.off`. */
removeListener: Off;
/** Call a TDLib method asynchronously. */
invoke: Invoke;
/** Same as `tdl.execute`. */
execute: Execute;
/**
* Close the client. This sends `{ _: 'close' }` and waits for
* `authorizationStateClosed`.
*/
close: () => Promise;
/**
* Get the TDLib version in the `major.minor.patch` format. Can throw an
* exception if the version (the `updateOption` update) is not (yet) received.
*/
getVersion: () => string;
/** For advanced use only. */
emit: Emit;
/**
* @deprecated Use `client.close` instead. The client will be automatically
* destroyed on `authorizationStateClosed`.
*/
destroy: () => void;
/** @deprecated Deprecated in TDLib v1.8.0, use tdl.setLogMessageCallback instead. */
setLogFatalErrorCallback: (fn: null | ((errorMessage: string) => void)) => void;
/** @deprecated Unstable */
pause: () => void;
/** @deprecated Unstable */
resume: () => void;
/** @deprecated Present for backward compatibility only, does nothing. */
connect: () => Promise;
/** @deprecated Use `client.login` instead. */
connectAndLogin: (getLoginDetails?: () => LoginDetails) => Promise;
/** @deprecated */
getBackendName: () => string;
/**
* @deprecated Use `tdl.configure` and `tdl.createClient` instead. See the
* tdl@7.3.1 entry in `CHANGELOG.md` for additional information. The new
* approach to create a client is (`tdl-tdlib-addon` is no longer needed):
* ```
* const tdl = require('tdl')
* tdl.configure({ tdjson: 'path to tdjson' }) // was: new TDLib('path to tdjson')
* const client = tdl.createClient({ apiId: 12345, apiHash: 'your api hash' })
* ```
* If tdjson is in the default location, then the `configure` line is
* optional.
*/
constructor(tdlibInstance: any, options: ClientOptions);
/** @deprecated Use `tdl.configure` and `tdl.createClient` instead. */
static create(tdlibInstance: any, options: ClientOptions): Client;
}
export type ClientOptions = {
/** Required. Can be obtained at https://my.telegram.org/ */
apiId?: number,
/** Required. Can be obtained at https://my.telegram.org/ */
apiHash?: string,
/** A relative path to the database directory. Defaults to `'_td_database'`. */
databaseDirectory?: string,
/** A relative path to the files directory. Defaults to `'_td_files'`. */
filesDirectory?: string,
/** An optional key for database encryption. */
databaseEncryptionKey?: string,
/** Use test telegram server. */
useTestDc?: boolean,
/**
* Raw TDLib parameters. These contain fields like application_version,
* device_model, etc. Defaults to:
* ```
* { use_message_database: true
* , use_secret_chats: false
* , system_language_code: 'en'
* , application_version: '1.0'
* , device_model: 'Unknown device'
* , system_version: 'Unknown'
* , enable_storage_optimizer: true }
* ```
*/
tdlibParameters?: TDLibParameters,
/**
* Advanced option. When set to true, the client does not emit updates if
* `connectionState` equals to `connectionStateUpdating`. See also the
* `ignore_background_updates` option in TDLib.
*/
skipOldUpdates?: boolean,
/**
* Advanced option. This disables handling of auth* updates, making `tdl` a
* relatively tiny wrapper. When set to true, you need to handle the
* `authorizationStateWaitTdlibParameters` update manually (and
* `authorizationStateWaitEncryptionKey` in TDLib < v1.8.6). The parameters
* should be passed to TDLib manually by calling `setTdlibParameters`. The
* `client.login` function will not work and should not be called. The options
* `tdlibParameters`, `apiId`, `apiHash`, `useTestDc`, `databaseDirectory`,
* `filesDirectory` will do nothing.
*/
bare?: boolean,
/** @deprecated Set `receiveTimeout` in `tdl.configure` instead. */
receiveTimeout?: number,
/** @deprecated Set the verbosity level in `tdl.configure` instead. */
verbosityLevel?: number | 'default',
/** @deprecated Use `verbosityLevel: 'default'` instead. */
useDefaultVerbosityLevel?: boolean,
/** @deprecated Use the `bare` option instead. */
disableAuth?: boolean,
/** @deprecated Does nothing. */
useMutableRename?: boolean
}
export type LoginUser = {
type: 'user',
/** Handler for `authorizationStateWaitPhoneNumber`, will be recalled on error. */
getPhoneNumber: (retry?: boolean) => Promise,
/** Handler for `authorizationStateWaitEmailAddress`, TDLib v1.8.6+ only. */
getEmailAddress: () => Promise,
/** Handler for `authorizationStateWaitEmailCode`, TDLib v1.8.6+ only. */
getEmailCode: () => Promise,
/** Handler for `authorizationStateWaitOtherDeviceConfirmation`, sends nothing. */
confirmOnAnotherDevice: (link: string) => void,
/** Handler for `authorizationStateWaitCode`, will be recalled on error. */
getAuthCode: (retry?: boolean) => Promise,
/** Handler for `authorizationStateWaitPassword`, will be recalled on error. */
getPassword: (passwordHint: string, retry?: boolean) => Promise,
/** Handler for `authorizationStateWaitRegistration`. */
getName: () => Promise<{ firstName: string, lastName?: string }>
}
export type LoginBot = {
/** You will be logged in as a bot. */
type: 'bot',
/**
* Handler for `authorizationStateWaitPhoneNumber`,
* sends `checkAuthenticationBotToken`, will be recalled on error.
*/
getToken: (retry?: boolean) => Promise
}
export type LoginDetails = Partial | LoginBot
export type StrictLoginDetails = LoginUser | LoginBot
/**
* This wraps any errors that are thrown in:
* - `client.on` handlers,
* - `client.login` handlers,
* - errors during calls to TDLib,
* - other internal tdl errors.
*/
export class TdlError extends Error {
readonly err: any
}
export type On =
& ((event: 'update', listener: (update: Td$Update) => void) => Client)
& ((event: 'error', listener: (err: Td$error | TdlError) => void) => Client)
& ((event: 'destroy', listener: () => void) => Client)
& ((event: 'auth-needed', listener: () => void) => Client)
& ((event: 'auth-not-needed', listener: () => void) => Client)
& ((event: 'response', listener: (res: any) => void) => Client)
export type Emit =
& ((event: 'update', update: Td$Update) => void)
& ((event: 'error', err: Td$error | TdlError) => void)
& ((event: 'destroy') => void)
& ((event: 'auth-needed') => void)
& ((event: 'auth-not-needed') => void)
& ((event: 'response', res: any) => void)
export type Off =
& ((event: 'update', listener: (...args: any[]) => any, once?: boolean) => void)
& ((event: 'error', listener: (...args: any[]) => any, once?: boolean) => void)
& ((event: 'destroy', listener: (...args: any[]) => any, once?: boolean) => void)
& ((event: 'auth-needed', listener: (...args: any[]) => any, once?: boolean) => void)
& ((event: 'auth-not-needed', listener: (...args: any[]) => any, once?: boolean) => void)
& ((event: 'response', listener: (...args: any[]) => any, once?: boolean) => void)
// NOTE: The destroy and response events are deprecated.
/** @deprecated Use ClientOptions */
export type StrictClientOptions = {
apiId?: number,
apiHash?: string,
databaseDirectory: string,
filesDirectory: string,
databaseEncryptionKey: string,
verbosityLevel: number | 'default',
useTestDc: boolean,
tdlibParameters: TDLibParameters,
skipOldUpdates: boolean,
bare: boolean,
receiveTimeout: number,
useDefaultVerbosityLevel: boolean,
disableAuth: boolean,
useMutableRename: boolean
}
/** @deprecated Use ClientOptions */
export type ConfigType = ClientOptions
// TDL, TDl exports exist for backward compatibility only.
export { Client as TDL, Client as Tdl }
|