tdl is a JavaScript wrapper for TDLib (Telegram Database Library), providing Node.js bindings to create custom Telegram clients or bots. Currently at version 8.1.0, it is actively maintained with releases often following new TDLib versions. A key differentiator is its direct, low-level integration with the native TDLib, allowing full control over Telegram API interactions, unlike higher-level bot libraries. It requires a separate installation or build of the `tdjson` shared library from TDLib itself. tdl ships with TypeScript type definitions, enabling robust development in modern JavaScript environments.
npm install tdlVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing `tdl` with `prebuilt-tdlib`, creating a client, handling errors, and observing authorization state changes during login.
Install `prebuilt-tdlib` (`npm install prebuilt-tdlib`) and configure tdl using `configure({ tdjson: getTdjson() })` or manually provide the path to `libtdjson.so`/`.dylib`/`.dll` via `configure({ tdjson: '/path/to/libtdjson.so' })`.Ensure `prebuilt-tdlib` installs a compatible TDLib version, or if building manually, use TDLib source version 1.8.0 or newer.
Install necessary build tools for your operating system. For Windows, install 'Desktop development with C++' from Visual Studio Installer. For Linux, `build-essential` and Python. For macOS, Xcode Command Line Tools.
Obtain your `apiId` and `apiHash` by logging in at `https://my.telegram.org/` under 'API development tools'.
Upgrade your Node.js environment to version 16.14.0 or higher.
Ensure `prebuilt-tdlib` is installed and `tdl.configure({ tdjson: getTdjson() })` is called before `createClient()`, or provide a direct path via `tdl.configure({ tdjson: '/path/to/libtdjson.so' })`.Install a C++ compiler (e.g., `build-essential` on Linux, Xcode Command Line Tools on macOS, Visual Studio Build Tools on Windows) and Python.
Verify your `apiId` and `apiHash` are correct and obtained from `https://my.telegram.org/`.
For ESM, use `import { createClient } from 'tdl'`. For CommonJS, use `const { createClient } = require('tdl')` if not using `tdl.configure()` first, or `const tdl = require('tdl')` and then `tdl.createClient()` after `tdl.configure()`.