docs: updated readmes

This commit is contained in:
alina 🌸 2024-03-06 21:20:44 +03:00
parent d64aa478cc
commit 6756c78065
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
8 changed files with 79 additions and 25 deletions

View file

@ -2,25 +2,48 @@
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_core.html) 📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_core.html)
Basic low-level MTProto implementation and auxiliary utilities. Platform-agnostic MTProto implementation and auxiliary utilities.
## Features ## Features
- **MTProto 2.0**: Implements the full MTProto protocol, including all the encryption and serialization - **MTProto 2.0**: Implements the full MTProto protocol, including all the encryption and serialization
- **2FA support**: Provides utilities for 2-step verification - **2FA support**: Provides utilities for 2-step verification
- **Hackable**: Bring your own storage, transport, and other components to customize the library to your needs - **Hackable**: Bring your own storage, transport, and other components to customize the library to your needs
- **Magical**: Handles reconnections, connection pooling, DC redirections and other stuff for you - **Magical**: Handles reconnections, connection pooling, DC redirections and other stuff for you
- **Web support**: Works in the browser with no additional configuration - **Updates handling**: Implements proper updates handling, including ordering and gap recovery (learn more)
- **High-level**: Includes a high-level API that wrap the MTProto APIs and provide a clean interface
- **Tree-shaking**: You can import just the methods you need, and the rest will not be included into the bundle
## Usage ## Usage
```ts ```ts
import { BaseTelegramClient } from '@mtcute/core' import { BaseTelegramClient } from '@mtcute/core/client.js'
const tg = new BaseTelegramClient({ const tg = new BaseTelegramClient({
apiId: 12345, apiId: 12345,
apiHash: '0123456789abcdef0123456789abcdef', apiHash: '0123456789abcdef0123456789abcdef',
crypto: new MyCryptoProvider(),
storage: new MyStorage(),
transport: () => new MyTransport(),
}) })
tg.call({ _: 'help.getConfig' }) tg.call({ _: 'help.getConfig' })
.then(console.log) .then(console.log)
``` ```
## Usage with high-level API
```ts
import { TelegramClient } from '@mtcute/core/client.js'
const tg = new TelegramClient({
// ... same options as above
})
tg.run({
phone: '+1234567890',
code: () => prompt('Enter the code:'),
password: 'my-password',
}, async (user) => {
console.log(`✨ logged in as ${user.displayName}`)
})
```

View file

@ -16,7 +16,7 @@ Then, install the package as usual. The native library will be built automatical
## Usage ## Usage
```typescript ```typescript
import { TelegramClient } from '@mtcute/client' import { TelegramClient } from '@mtcute/core'
import { NodeNativeCryptoProvider } from '@mtcute/crypto-node' import { NodeNativeCryptoProvider } from '@mtcute/crypto-node'
const tg = new TelegramClient({ const tg = new TelegramClient({

View file

@ -3,7 +3,7 @@
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_dispatcher.html) 📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_dispatcher.html)
🧐 [Guide](https://mtcute.dev/guide/dispatcher/intro.html) 🧐 [Guide](https://mtcute.dev/guide/dispatcher/intro.html)
Dispatcher and bot framework based on @mtcute/client. Dispatcher and bot framework based on @mtcute/core.
## Features ## Features
- **Straightforward**: Simple and expressive API - **Straightforward**: Simple and expressive API
@ -15,9 +15,9 @@ Dispatcher and bot framework based on @mtcute/client.
## Usage ## Usage
```ts ```ts
import { NodeTelegramClient, Dispatcher } from '@mtcute/node' import { TelegramClient, Dispatcher } from '@mtcute/node'
const tg = new NodeTelegramClient({ ... }) const tg = new TelegramClient({ ... })
const dp = Dispatcher.for(tg) const dp = Dispatcher.for(tg)
dp.onNewMessage(async (msg) => { dp.onNewMessage(async (msg) => {

View file

@ -2,7 +2,7 @@
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_file_id.html) 📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_file_id.html)
This package is used internally by `@mtcute/client` to parse, serialize This package is used internally by `@mtcute/core` to parse, serialize
and manipulate TDLib and Bot API compatible File IDs, but can also be used and manipulate TDLib and Bot API compatible File IDs, but can also be used
for any other purposes. for any other purposes.

View file

@ -2,16 +2,20 @@
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_node.html) 📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_node.html)
All-in-one package for NodeJS. Includes support for native crypto addon Node.js support package for mtcute. Includes:
(must be installed separately, `@mtcute/crypto-node`), terminal I/O via - Support for native crypto addon (must be installed separately, `@mtcute/crypto-node`)
`readline` and includes HTML and Markdown parsers. - Terminal I/O via `readline`
- SQLite storage (`@mtcute/sqlite`)
- TCP transport
- `TelegramClient` implementation using the above
- HTML and Markdown parsers
## Usage ## Usage
```typescript ```typescript
import { NodeTelegramClient } from '@mtcute/node' import { TelegramClient } from '@mtcute/node'
const tg = new NodeTelegramClient({ const tg = new TelegramClient({
apiId: 12345, apiId: 12345,
apiHash: 'abcdef', apiHash: 'abcdef',
storage: 'my-account' storage: 'my-account'

View file

@ -1,6 +1,6 @@
module.exports = { module.exports = {
extends: ['../../.config/typedoc/config.base.cjs'], extends: ['../../.config/typedoc/config.base.cjs'],
entryPoints: ['./index.ts'], entryPoints: ['./src/index.ts'],
externalPattern: [ externalPattern: [
'../core/**', '../core/**',
'../html-parser/**', '../html-parser/**',

View file

@ -1,17 +1,19 @@
# @mtcute/node # @mtcute/web
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_node.html) 📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_web.html)
All-in-one package for NodeJS. Includes support for native crypto addon Web support package for mtcute. Includes:
(must be installed separately, `@mtcute/crypto-node`), terminal I/O via - WASM crypto provider
`readline` and includes HTML and Markdown parsers. - Websocket transport
- IndexedDB storage
- `TelegramClient` implementation using the above
## Usage ## Usage
```typescript ```typescript
import { NodeTelegramClient } from '@mtcute/node' import { TelegramClient } from '@mtcute/web'
const tg = new NodeTelegramClient({ const tg = new TelegramClient({
apiId: 12345, apiId: 12345,
apiHash: 'abcdef', apiHash: 'abcdef',
storage: 'my-account' storage: 'my-account'
@ -21,3 +23,31 @@ tg.run(async (user) => {
console.log(`✨ logged in as ${user.displayName}`) console.log(`✨ logged in as ${user.displayName}`)
}) })
``` ```
## Usage with workers
You can also use this package with web workers to offload most of the heavy lifting to a separate thread:
```typescript
// worker.ts
import { BaseTelegramClient, TelegramWorker } from '@mtcute/web'
const client = new BaseTelegramClient({
apiId: 12345,
apiHash: 'abcdef',
storage: 'my-account'
})
new TelegramWorker({ client })
// main.ts
import { TelegramClient, TelegramWorkerPort } from '@mtcute/web'
const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }) // or SharedWorker
const port = new TelegramWorkerPort({ worker })
const tg = new TelegramClient({ client: port })
tg.run({}, async (user) => {
console.log(`✨ logged in as ${user.displayName}`)
})
```

View file

@ -1,10 +1,7 @@
module.exports = { module.exports = {
extends: ['../../.config/typedoc/config.base.cjs'], extends: ['../../.config/typedoc/config.base.cjs'],
entryPoints: ['./index.ts'], entryPoints: ['./src/index.ts'],
externalPattern: [ externalPattern: [
'../core/**', '../core/**',
'../html-parser/**',
'../markdown-parser/**',
'../sqlite/**',
], ],
} }