Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
eilvelia committed Oct 10, 2023
1 parent d5cfe41 commit dc10841
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const tdl = require('tdl')
// If libtdjson is not present in the system search paths, the path to the
// libtdjson shared library can be set manually, e.g.:
// tdl.configure({ tdjson: '/usr/local/lib/libtdjson.dylib' })
// The library prefix can be set separate from the library name,
// The library directory can be set separate from the library name,
// example to search for libtdjson in the directory of the current script:
// tdl.configure({ libdir: __dirname })

Expand All @@ -81,8 +81,8 @@ client.on('update', update => {
})

async function main () {
// Log in to a Telegram account. By default, with no arguments, this function will ask
// for phone number etc. in the console. Instead of logging in as a normal user,
// Log in to a Telegram account. By default, with no arguments, this function will
// ask for phone number etc. in the console. Instead of logging in as a user,
// it's also possible to log in as a bot using `client.loginAsBot('<TOKEN>')`.
await client.login()

Expand Down Expand Up @@ -110,7 +110,7 @@ The API list of TDLib methods, which are called using `client.invoke`, can be fo
- https://core.telegram.org/tdlib/docs/annotated.html (possibly outdated)
- or in the [td_api.tl][] file in the TDLib repository.

[td_api.tl]: https://github.com/tdlib/td/blob/66234ae2537a99ec0eaf7b0857245a6e5c2d2bc9/td/generate/scheme/td_api.tl
[td_api.tl]: https://github.com/tdlib/td/blob/2589c3fd46925f5d57e4ec79233cd1bd0f5d0c09/td/generate/scheme/td_api.tl

In the TDLib documentation, the `bytes` type means a **base64-encoded** string.
`int64` accepts either a number or a string, pass string for large numbers.
Expand All @@ -124,7 +124,7 @@ information on how to use TDLib (tdl handles the authorization part with
`client.login`). Note that the TDLib JSON interface actually sends a `@type`
field, but tdl renames it to `_`.

<!-- TODO: Add a guide on how to read the tl scheme or similar? -->
<!-- TODO: Add a guide on how to read the tl schema or similar? -->

Some short examples are available in the [examples/](examples/) directory.

Expand Down Expand Up @@ -289,7 +289,7 @@ await client.loginAsBot('YOUR_BOT_TOKEN') // Enter your token from @BotFather

#### `client.on(event: string, callback: Function) => Client`

Attach an event listener to receive updates.
Attach an event listener to receive updates and other events.

```javascript
function onUpdate (update) {
Expand All @@ -302,9 +302,11 @@ client.on('error', console.error)
Ideally, you should always have a listener on `client.on('error')`.
There is no default listener, all errors will be ignored otherwise.

You can consider using reactive libraries like RxJS or most.js for convenient event processing.
You can consider using reactive libraries like RxJS or most.js for convenient
event processing.

Some other rarely-used events also exist and are described in the TypeScript interface.
Some other rarely-used events also exist and are described in the TypeScript
interface.

`client.addListener` is an alias for `client.on`.

Expand All @@ -317,9 +319,10 @@ Attach a one-time listener.
Remove an event listener.

```javascript
const listener = v => {
console.log('New update:', v)
client.off('update', listener) // Removes the listener
const listener = u => {
console.log('New update:', u)
if (u?.authorization_state?._ === 'authorizationStateReady')
client.off('update', listener) // Removes the listener
}
client.on('update', listener)
```
Expand Down Expand Up @@ -356,6 +359,14 @@ await client.invoke({
})
```

#### `client.close() => Promise<void>`

Close the TDLib client.

```javascript
await client.close()
```

#### `tdl.execute(query: Object) => (Object | null)`

Call a TDLib method synchronously. This function can be used only with the
Expand All @@ -368,21 +379,12 @@ const res = tdl.execute({
})
```

#### `client.execute(query: Object) => (Object | null)`

Same as `tdl.execute`.

#### `client.close() => Promise<void>`

Close the TDLib client.

```javascript
await client.close()
```
`client.execute` is the same as `tdl.execute`.

---
#### `tdl.setLogMessageCallback(maxVerbosityLevel: number, cb: Function | null) => void`

For the full API, see the [index.d.ts](packages/tdl/index.d.ts) file.
Set the callback that is called when a message is added to the TDLib log. This
corresponds to the `td_set_log_message_callback` tdjson function.

<a name="types"></a>
## Types
Expand Down Expand Up @@ -469,7 +471,7 @@ https://github.com/nodejs/node-gyp/issues/65#issuecomment-368820565.
- `Error while reading RSA public key`

You can get this error if libtdjson is dynamically linked against OpenSSL and
some of the symbols got resolved to Node.js instead of the system OpenSSL.
some of the symbols got resolved into Node.js instead of the system OpenSSL.

Note that Node.js also uses OpenSSL (the distributed binaries are statically
linked against it) and exports the OpenSSL symbols. In the result, there are
Expand Down
24 changes: 16 additions & 8 deletions packages/prebuilt-tdlib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ Supported systems:
- macOS x86_64, arm64 (universal, requires macOS >= 10.14)
- Windows x86_64

To install `prebuilt-tdlib` for e.g. TDLib v1.8.14, run:
To install `prebuilt-tdlib` for e.g. TDLib v1.8.19, run:

```console
$ npm install prebuilt-tdlib@td-1.8.14
$ npm install prebuilt-tdlib@td-1.8.19
```

`prebuilt-tdlib` can be installed for other TDLib versions, run
`$ npm info prebuilt-tdlib dist-tags` to get the list of available versions
(or see the "npm tags" section below).

> **Note**: Before `prebuilt-tdlib@td-1.8.14`, the Linux binary was built on
> Ubuntu 20.04 requiring glibc >= 2.31, and macOS arm64 was not supported.
> Currently, the Linux build environment is based on CentOS 7.
> The macOS arm64 binary isn't tested in the CI.
> **Note**: Before `prebuilt-tdlib@td-1.8.14` (2023-06-26), the Linux binary was
> built on Ubuntu 20.04 requiring glibc >= 2.31, and macOS arm64 was not
> supported. Currently, the Linux build environment is based on CentOS 7. The
> macOS arm64 binary isn't tested in the CI.
## Usage

Expand All @@ -53,6 +53,9 @@ tdl.configure({ tdjson: getTdjson() })
// ...
```

The pre-built libraries can also be extracted and used with any other library
or programming language.

## Versioning conventions

> **Note**: This information is mostly for maintaining `prebuilt-tdlib`, it
Expand All @@ -78,22 +81,27 @@ TDLib v1.8.5, just run `npm install prebuilt-tdlib@td-1.8.5`, or
`npm install prebuilt-tdlib@td-1.8.0` for TDLib v1.8.0. This will automatically
install the needed version of `prebuilt-tdlib`.

Additionaly, TDLib's versioning is weird, and some of the `prebuilt-tdlib`
releases are not connected to a specific tag release in the TDLib repository.
Additionaly, TDLib's releasing process is weird, and most of the
`prebuilt-tdlib` releases are not connected to a specific tag release in the
TDLib repository.

The releases of the `prebuilt-tdlib` npm package are not git-tagged.

## npm tags

- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/latest.svg)](https://www.npmjs.com/package/prebuilt-tdlib)
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/stable.svg)](https://www.npmjs.com/package/prebuilt-tdlib)

<!-- Add new versions below -->
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.19.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.19) tdlib [2589c3fd46925f5d57e4ec79233cd1bd0f5d0c09](https://github.com/tdlib/td/commit/2589c3fd46925f5d57e4ec79233cd1bd0f5d0c09)
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.14.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.14) tdlib [66234ae2537a99ec0eaf7b0857245a6e5c2d2bc9](https://github.com/tdlib/td/commit/66234ae2537a99ec0eaf7b0857245a6e5c2d2bc9)
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.12.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.12) tdlib [70bee089d492437ce931aa78446d89af3da182fc](https://github.com/tdlib/td/commit/70bee089d492437ce931aa78446d89af3da182fc)
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.7.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.7) tdlib [de5379f00b6af7686f197037ca3b494e6277e523](https://github.com/tdlib/td/commit/de5379f00b6af7686f197037ca3b494e6277e523)
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.5.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.5) tdlib [d9cfcf88fe4ad06dae1716ce8f66bbeb7f9491d9](https://github.com/tdlib/td/commit/d9cfcf88fe4ad06dae1716ce8f66bbeb7f9491d9)
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.8.0.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.8.0)

Outdated versions:

- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.7.0.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.7.0)
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.6.0.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.6.0)
- [![npm](https://img.shields.io/npm/v/prebuilt-tdlib/td-1.5.0.svg)](https://www.npmjs.com/package/prebuilt-tdlib/v/td-1.5.0)

0 comments on commit dc10841

Please sign in to comment.