Git Product home page Git Product logo

mtcute's People

Contributors

es3n1n avatar mtcute-bot avatar teidesu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mtcute's Issues

aggressive caching ("tdlib mode")

unlike tdlib, mtcute currently only caches the bare minimum needed to function. however, in many cases it makes sense to cache stuff locally, just like tdlib.

  • cache results (*NotModified constructors + hash parameter)
  • messages database
  • dialogs database
  • chat members database
  • "full" peers database
  • TBA...

ideally this should be done in a modular (and tree-shakeable) way - maybe some kind of request intercepting system would make sense here?

deno support

  • support publishing to jsr.io (#27)
  • stop globally depending on @types/node wontfix
  • @mtcute/deno package with platform-specific transport, crypto and storage (#52)
  • refactor proxy packages to be platform-agnostic, export the platform-specific implementations from the platform packages - requires better networking abstractions

prebuilt binaries for @mtcute/crypto-node

we should migrate to building makefiles directly, because node-gyp depends on python and it sucks, and also add pre-built binaries for common platforms.

it's also broken on python 3.12+ due to nodejs/node-gyp#2869

improve logging for dispatcher

currently dispatcher doesn't have any logging on its own. it would probably be quite useful if it logged events and whether something matched them or not

Expo/React Native

Does this library works with React Native/Expo projects? For example, gramjs dont work because of crypto, but this library use a different dependency

properly handle random_id

currently when sending messages/stories we expect the server to return updates with the actual message. however this might not actually be the case, so we should instead rely on random_id and updateMessageID

[Bug]: Can't call `resolvePeer` - `400 BOT_INVALID`.

Sometimes I receive error (see logs sections) without no reason. It can happens at random time.

To Reproduce

  1. Call resolvePeer(899433974)
  2. With some chance you will receive error

p.s: 899433974 is @odesli_bot.

Expected behavior

Logs

image

Environment

OS: Windows 11 (WSL 2 with Ubuntu 22.04).
Runtime: Node.js v21.6.1.
mtcute version: ^0.7.0.

Additional context
No additional context.

future auth tokens

bare minimum - accept them in .start() method and return them on .logOut()

[Bug]: Unknown object undefined when call `exportSession()`.

Hello, dear developer! When I call exportSession() I receive error Error: Unknown object undefined.

To Reproduce

  1. Log in to your account.
  2. Call exportSession().
  3. See result.

Expected behavior

Retrieve session string.

Logs

Error: Unknown object undefined
    at TlBinaryWriter.object (file:///home/lwjerri/projects/SpotiGram/node_modules/.pnpm/@[email protected]/node_modules/@mtcute/tl-runtime/esm/writer.js:243:19)
    at writeStringSession (file:///home/lwjerri/projects/SpotiGram/node_modules/.pnpm/@[email protected]/node_modules/@mtcute/core/esm/utils/string-session.js:22:12)
    at BaseTelegramClient.exportSession (file:///home/lwjerri/projects/SpotiGram/node_modules/.pnpm/@[email protected]/node_modules/@mtcute/core/esm/highlevel/base.js:168:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async saveSession (file:///home/lwjerri/projects/SpotiGram/dist/app.js:133:27)
    at async file:///home/lwjerri/projects/SpotiGram/dist/app.js:224:12

Environment

  • OS: Windows 11 (WSL 2 with Ubuntu 22.04).
  • Runtime: Node.js v21.6.1.
  • mtcute version: ^0.7.0.

Additional context
I'm use NodeTelegramClient client instance from @mtcute/node package.

[Bug]: `Could not locate the bindings file.` after `pnpm i -r` command.

SQLite can't find the session file after pnpm i -r command.

To Reproduce

  1. Run pnpm create @mtcute/bot my-awesome-bot.
  2. Wait until all dependencies are installed.
  3. Delete the node_modules folder.
  4. Install all packages with the pnpm i -r command.
  5. Run pnpm run run.

Expected behavior

An application must start as expected, without any errors.

Logs

`pnpm run run` output

LWJerri :: test/bug-reproduce » pnpm run run

[email protected] run /home/lwjerri/projects/SpotiGram/test/bug-reproduce
tsc && dotenv node ./dist/index.js

Error: Could not locate the bindings file. Tried:
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/Debug/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/Release/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/out/Debug/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/Debug/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/out/Release/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/Release/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/default/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/compiled/21.6.1/linux/x64/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/release/install-root/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/debug/install-root/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/default/install-root/better_sqlite3.node
→ /home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/binding/node-v120-linux-x64/better_sqlite3.node
at bindings (/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/bindings/bindings.js:126:9)
at new Database (/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:48:64)
at Database (/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/database.js:11:10)
at SqliteStorage.load (file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/sqlite/esm/index.js:267:20)
at NodeTelegramClient._loadStorage (file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/core/esm/base-client.js:75:34)
at NodeTelegramClient.connect (file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/core/esm/base-client.js:103:20)
at async NodeTelegramClient.call (file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/core/esm/base-client.js:158:13)
at async start (file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/client/esm/methods/auth/start.js:30:20)
at async NodeTelegramClient._start [as start] (file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/client/esm/client.js:1017:22) {
tries: [
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/Debug/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/Release/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/out/Debug/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/Debug/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/out/Release/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/Release/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/build/default/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/compiled/21.6.1/linux/x64/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/release/install-root/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/debug/install-root/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/addon-build/default/install-root/better_sqlite3.node',
'/home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/binding/node-v120-linux-x64/better_sqlite3.node'
]
}
file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/sqlite/esm/index.js:315
this._db.close();
^

TypeError: Cannot read properties of undefined (reading 'close')
at SqliteStorage._destroy (file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/sqlite/esm/index.js:315:18)
at file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/sqlite/esm/index.js:158:61
at process.eventHandler (file:///home/lwjerri/projects/SpotiGram/test/bug-reproduce/node_modules/.pnpm/@mtcute[email protected]/node_modules/@mtcute/core/esm/utils/platform/exit-hook.js:13:13)
at process.emit (node:events:519:28)

Node.js v21.6.1
 ELIFECYCLE  Command failed with exit code 1.

Environment

  • OS: Windows 11 (WSL 2 with Ubuntu 22.04).
  • Runtime: Node.js v21.6.1.
  • mtcute version: ^0.6.0.

Additional context
Some developers can use monorepository with this package, but it will not work, because we have this error.

split long messages

add a high-level method sendTextMulti which would split the message into multiple if the text turns out to be too long.

we should probably also make a util to split TextWithEntities so users can implement it on their own for media messages (i'm not sure what the behavior should be on those)

storage doesn't get saved after logging in

How to reproduce

import { NodeTelegramClient } from '@mtcute/node'
import { Dispatcher, filters } from '@mtcute/dispatcher'

const tg = new NodeTelegramClient({
    apiId: 3328759,
    apiHash: 'e6bb1e8c05bd21386e33a5d89fe2e966',
    storage: 'bot-data/my-account',
    logLevel: 10
})

tg.run({
    phone: () => tg.input('phone > '),
    code: () => tg.input('code > '),
    password: () => tg.input('password > ')
}, async (self) => {
    console.log(`logged in as ${self.displayName}`)
})

  • run the above code
  • ctrl-c immediately after logging
  • run the code again

Expected

the authorization is persisted

Actual

it is not

Move updates handling to `core`?

Currently updates handling is done in updates.ts file of client package, and core package only exposes a callback that is called whenever tl.TypeUpdates is received.

Correctly handling updates is pretty complex and should be done by a library, but I'm not entirely sure about moving updates handling to core since when using core, user might want to do something simple, or something very complex with custom storage schemes, etc., and in both cases updates handing isn't really needed.

Also this would be a breaking change in the APIs.

esm rewrite for @mtcute/tl codegen

currently @mtcute/tl is basically:

  • a large map of constructor id -> reader function
  • a large map of constructor name -> writer function
  • a large union type in typescript

instead, we could do something along:

const messages_getMessages_write = (w) => { ... }
export function messages_getMessages(obj) {
  write: messages_getMessages_write,
  result: read.Updates,
  id: 12345678,
  obj,
}

for methods and similarly for objects (and put readers into a separate esm namespace - arguably, that's a much more rarely used case in the surface api).

// so, this
tg.call({ _: 'auth.exportAuthorization', ... })
// becomes this
tg.call(tl.auth.exportAuthorization({ ... }))

pros

  • will make @mtcute/tl tree-shakeable
  • will probably improve type checking performance (#30)
  • we'll finally get rid of commonjs nonsense in mtcute and allow us to become esm-only
  • end users will be able to easily invoke custom tl methods as we will no longer use

cons

  • will be a major breaking change in the surface api
  • currently unclear how to type the thing
  • this will break the current way of overriding the schema. while it will provide some alternative, some cases will be missed

open questions

  • how to handle error descriptions?
  • what should reader functions return, plain objects?
    • if so, how do we transform those into something that can be written?
    • or do we even need to?

PHOTO_EXT_INVALID when sending photos from buffer

To Reproduce

const buffer = Buffer.from(b64, 'base64')
const photo = InputMedia.photo(buffer)
const phtemp = await tg.uploadMedia(photo)

Expected behavior

works fine

Environment

  • OS: [e.g. windows]
  • Runtime: [e.g. Node 18.12.1, Chrome 97.0.0]
  • mtcute version: [e.g. 0.1.0]

Additional context

for some reason mime is not enough and we should also provide a valid file extension for that mime

Abnormally slow performance of VSCode Intellisense

After any change to the source code in a file with mtcute imports Intellisense operations take up to 5-10 sec to perform.

To Reproduce

Try to invoke .call method for TelegramClient object, e.g.:

const tg = new TelegramClient({...});
tg.call({...})

After typing "tg." it takes 5-10 sec to show method list.

Expected behavior

"Go to Definition" and "Autocomplete" operations perform in less than 1 sec.

Logs

Info 492 [17:26:49.904] request:
{
"seq": 99,
"type": "request",
"command": "quickinfo",
"arguments": {
"file": "/Users/.../mtcute/test/index.ts",
"line": 42,
"offset": 27
}
}
Perf 493 [17:26:49.916] 99::quickinfo: elapsed time (in milliseconds) 12.0900

Environment

  • OS: MacOS 14.4.1
  • Runtime: Node.js 20
  • mtcute version: 0.10.1

Additional context
The codesandbox repo below can be opened locally with VSCode.

CodeSandbox

Provide context in handlers and filters

Currently pre-update middleware in Dispatcher allows user to add additional fields to the update info object:

interface TimerContext {
    start: number
}

dp.onPreUpdate<TimerContext>((upd) => {
    upd.start = Date.now()
})

dp.onPostUpdate<TimerContext>((handled, upd) => {
    if (handled) {
        console.log(`handled ${upd.type} in ${Date.now() - upd.start} ms`)
    }
})

This additional context is currently only available in post-update middleware and error handler, and not handlers/filters.

I'm not sure if providing it there would be useful, and if it would, not sure how to implement it in a way that is non-obtrusive, intuitive and type-safe.

improve wasm allocs

ctr256 can work in place, we can reduce the number of allocs there. also check if we can use some pre-alloced pool for small chunks

@mtcute/core/client.js isn't resolved under `module: esnext`

/subj. was reported in tg chat

To Reproduce

create a node.js project, put "module": "esnext" in tsconfig.json, try compiling this code:

import { TelegramClient } from '@mtcute/node'

const tg = new TelegramClient({})
tg.exportSession() // <- error, `exportSession` not found

Expected behavior

works fine

Logs

n/a

Environment

  • OS: n/a
  • Runtime: node any, ts
  • mtcute version: 0.10.0

Additional context
this happens because ts can't resolve @mtcute/core/client.js under esnext, because it ignores exports field in package.json:

image

we should probably also generate the client.js/utils.js/etc. files at root dir based on our package.json exports in build script, but this is blocked by #27

add `fmt`, an parser-free alternative to html/md functions

something similar to what grammy has:

await tg.sendText(fmt`hi, ${bold(user.name)}!`)

this becomes quite tedious and unreadable though with nested entities:

await tg.sendText(
  fmt`${bold(fmt`hi, ${italic(user.name)}`)}!`
)

idk if there's a way to prevent this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.