mtcute / mtcute Goto Github PK
View Code? Open in Web Editor NEWmodern typescript library for mtproto. supports browsers, node/bun, deno and more!
Home Page: https://mtcute.dev
License: MIT License
modern typescript library for mtproto. supports browsers, node/bun, deno and more!
Home Page: https://mtcute.dev
License: MIT License
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.
*NotModified
constructors + hash
parameter)ideally this should be done in a modular (and tree-shakeable) way - maybe some kind of request intercepting system would make sense here?
@types/node
@mtcute/deno
package with platform-specific transport, crypto and storage (#52)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
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
Does this library works with React Native/Expo projects? For example, gramjs dont work because of crypto, but this library use a different dependency
Tracking issue for:
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
Sometimes I receive error (see logs sections) without no reason. It can happens at random time.
resolvePeer(899433974)
p.s: 899433974 is @odesli_bot.
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.
bare minimum - accept them in .start()
method and return them on .logOut()
Hello, dear developer! When I call exportSession()
I receive error Error: Unknown object undefined
.
exportSession()
.Retrieve session string.
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
Windows 11 (WSL 2 with Ubuntu 22.04)
.Node.js v21.6.1
.^0.7.0
.Additional context
I'm use NodeTelegramClient
client instance from @mtcute/node
package.
SQLite can't find the session file after pnpm i -r
command.
pnpm create @mtcute/bot my-awesome-bot
.node_modules
folder.pnpm i -r
command.pnpm run run
.An application must start as expected, without any errors.
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.
Windows 11 (WSL 2 with Ubuntu 22.04)
.Node.js v21.6.1
.^0.6.0
.Additional context
Some developers can use monorepository with this package, but it will not work, because we have this error.
I found this comment alik0211/mtproto-core#229 (comment) that has code for storage and transport on cloudflare workers , these are codes : https://github.com/Legend1991/mtproto-core/tree/master/envs/cloudflare
Could you please give me a code example how can i use that (exp. usage in my-awesome-bot template)?
/subj
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)
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}`)
})
the authorization is persisted
it is not
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.
implement file reference storage like described here: https://core.telegram.org/api/file_reference
currently @mtcute/tl is basically:
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({ ... }))
@mtcute/tl
tree-shakeableconst buffer = Buffer.from(b64, 'base64')
const photo = InputMedia.photo(buffer)
const phtemp = await tg.uploadMedia(photo)
works fine
Additional context
for some reason mime is not enough and we should also provide a valid file extension for that mime
After any change to the source code in a file with mtcute imports Intellisense operations take up to 5-10 sec to perform.
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.
"Go to Definition" and "Autocomplete" operations perform in less than 1 sec.
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
Additional context
The codesandbox repo below can be opened locally with VSCode.
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.
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
/subj. was reported in tg chat
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
works fine
n/a
Additional context
this happens because ts can't resolve @mtcute/core/client.js
under esnext, because it ignores exports
field in package.json:
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.