teleproto 1.225.1 → 1.225.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.txt → LICENSE} +3 -6
- package/README.md +67 -102
- package/Version.d.ts +1 -1
- package/Version.js +1 -1
- package/client/users.js +1 -1
- package/network/MTProtoState.d.ts +14 -18
- package/network/MTProtoState.js +14 -18
- package/package.json +5 -7
package/{LICENSE.txt → LICENSE}
RENAMED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
4
|
-
|
|
5
|
-
This project, teleproto, is an independent work originally derived from GramJS.
|
|
6
|
-
GramJS is an open source project licensed under the MIT License.
|
|
7
|
-
Portions of teleproto are adapted from GramJS and remain subject to the MIT terms.
|
|
3
|
+
Copyright (c) 2019 GramJS
|
|
4
|
+
Copyright (c) 2025-present sanyok12345
|
|
8
5
|
|
|
9
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
7
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -22,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
22
19
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
20
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
21
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
-
SOFTWARE.
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,150 +1,115 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/teleproto)
|
|
2
|
+
[](./LICENSE)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
<img src="https://img.shields.io/npm/v/teleproto" alt="npm version">
|
|
5
|
-
<img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen" alt="node version">
|
|
6
|
-
<img src="https://img.shields.io/badge/language-TypeScript-3178c6" alt="typescript">
|
|
7
|
-
<img src="https://img.shields.io/badge/license-MIT-blue" alt="license">
|
|
8
|
-
<a href="https://t.me/teleproto"><img src="https://img.shields.io/badge/Telegram-Chat-26A5E4?logo=telegram" alt="telegram chat"></a>
|
|
9
|
-
</p>
|
|
4
|
+
This project was forked from the open source GramJS project in 2025 and is now developed independently.
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
`teleproto` is a high-performance fork of GramJS focused on clean API ergonomics, runtime reliability, and up-to-date Telegram layers.
|
|
6
|
+
This README is just a fast *quick start*. Ongoing discussion happens in the [Telegram chat](https://t.me/teleproto).
|
|
13
7
|
|
|
14
|
-
|
|
8
|
+
# What is teleproto?
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
- **TypeScript-friendly**: Strong typings across client methods, events, sessions, and TL objects.
|
|
18
|
-
- **Session options**: Use `StringSession` for portability or `StoreSession` for local persistence.
|
|
19
|
-
- **Event system**: Handle updates with builders like `NewMessage`, `EditedMessage`, `CallbackQuery`, and more.
|
|
20
|
-
- **Examples included**: Ready-to-run scripts in `teleproto_examples`.
|
|
10
|
+
teleproto is a TypeScript client for Telegram's MTProto API — the same protocol Telegram's own apps speak. Through it, your code gets the full account surface: userbots, multi-account automation, file transfer, raw TL invocation when you need it. If you only need to push notifications from a bot, the official Bot API is simpler; teleproto exists for everything *beyond* that.
|
|
21
11
|
|
|
22
|
-
|
|
12
|
+
# Installing teleproto
|
|
23
13
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
% npm install teleproto
|
|
15
|
+
|
|
16
|
+
Pure JavaScript, no native build step — installs cleanly on Alpine, ARM, and serverless runtimes.
|
|
27
17
|
|
|
28
|
-
|
|
18
|
+
# Connecting to Telegram
|
|
29
19
|
|
|
30
|
-
|
|
31
|
-
2. Create an app in **API development tools**
|
|
32
|
-
3. Copy your `api_id` and `api_hash`
|
|
20
|
+
You need an `api_id` and `api_hash` from <https://my.telegram.org>. Then:
|
|
33
21
|
|
|
34
22
|
```ts
|
|
35
23
|
import { TelegramClient } from "teleproto";
|
|
36
24
|
import { StringSession } from "teleproto/sessions";
|
|
37
|
-
import
|
|
25
|
+
import { createInterface } from "node:readline/promises";
|
|
26
|
+
|
|
27
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
38
28
|
|
|
39
|
-
const apiId =
|
|
40
|
-
const apiHash = "
|
|
29
|
+
const apiId = 0; // from https://my.telegram.org
|
|
30
|
+
const apiHash = ""; // from https://my.telegram.org
|
|
41
31
|
const session = new StringSession("");
|
|
42
32
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
output: process.stdout,
|
|
33
|
+
const client = new TelegramClient(session, apiId, apiHash, {
|
|
34
|
+
connectionRetries: 5,
|
|
46
35
|
});
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
await client.start({
|
|
57
|
-
phoneNumber: async () => await ask("Phone number: "),
|
|
58
|
-
password: async () => await ask("2FA password (if enabled): "),
|
|
59
|
-
phoneCode: async () => await ask("Code from Telegram: "),
|
|
60
|
-
onError: (err) => console.error(err),
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
console.log("Connected as:", (await client.getMe())?.username || "unknown");
|
|
64
|
-
console.log("String session:\n", client.session.save());
|
|
37
|
+
await client.start({
|
|
38
|
+
phoneNumber: () => rl.question("Phone: "),
|
|
39
|
+
password: () => rl.question("2FA password: "),
|
|
40
|
+
phoneCode: () => rl.question("Code: "),
|
|
41
|
+
onError: console.error,
|
|
42
|
+
});
|
|
65
43
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
rl.close();
|
|
69
|
-
}
|
|
44
|
+
console.log(await client.getMe());
|
|
45
|
+
console.log("Session string:", client.session.save());
|
|
70
46
|
|
|
71
|
-
|
|
47
|
+
rl.close();
|
|
72
48
|
```
|
|
73
49
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Use `StringSession` when you want to store auth as a single string:
|
|
50
|
+
The session string is your saved login. Drop it back into `new StringSession(saved)` next time and skip the auth flow entirely.
|
|
77
51
|
|
|
78
|
-
|
|
79
|
-
import { StringSession } from "teleproto/sessions";
|
|
80
|
-
const session = new StringSession("");
|
|
81
|
-
```
|
|
52
|
+
# Sending and receiving
|
|
82
53
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
import { StoreSession } from "teleproto/sessions";
|
|
87
|
-
const session = new StoreSession("teleproto_session");
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Events
|
|
54
|
+
Send a message, listen for incoming ones:
|
|
91
55
|
|
|
92
56
|
```ts
|
|
93
57
|
import { NewMessage } from "teleproto/events";
|
|
94
58
|
|
|
59
|
+
await client.sendMessage("me", { message: "hello from teleproto" });
|
|
60
|
+
|
|
95
61
|
client.addEventHandler(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (/^hello$/i.test(text.trim())) {
|
|
99
|
-
await event.message.reply({ message: "Hi there!" });
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
new NewMessage({})
|
|
62
|
+
(event) => console.log(event.message.message),
|
|
63
|
+
new NewMessage({}),
|
|
103
64
|
);
|
|
104
65
|
```
|
|
105
66
|
|
|
106
|
-
|
|
67
|
+
# Raw MTProto API
|
|
68
|
+
|
|
69
|
+
Every method in Telegram's TL schema is callable directly through `Api.*`. teleproto follows the schema layer-for-layer, so what Telegram adds is usually available here within days.
|
|
107
70
|
|
|
108
71
|
```ts
|
|
109
72
|
import { Api } from "teleproto";
|
|
110
73
|
|
|
111
|
-
const
|
|
112
|
-
new Api.help.GetConfig()
|
|
113
|
-
);
|
|
114
|
-
console.log(result);
|
|
74
|
+
const config = await client.invoke(new Api.help.GetConfig());
|
|
115
75
|
```
|
|
116
76
|
|
|
117
|
-
|
|
77
|
+
# Versioning
|
|
118
78
|
|
|
119
|
-
|
|
79
|
+
teleproto uses a three-part version `MAJOR.LAYER.PATCH`:
|
|
120
80
|
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
|
|
124
|
-
-
|
|
81
|
+
- **MAJOR** — bumped on breaking API changes in teleproto itself.
|
|
82
|
+
- **LAYER** — the Telegram TL schema layer the release ships against
|
|
83
|
+
(e.g. `1.225.x` ships layer 225).
|
|
84
|
+
- **PATCH** — fixes and non-breaking improvements within the same layer.
|
|
125
85
|
|
|
126
|
-
|
|
86
|
+
This stays compatible with npm's range syntax:
|
|
127
87
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
88
|
+
- `^1.225.0` accepts new layers and patches — recommended default.
|
|
89
|
+
- `~1.225.0` sticks to layer 225 only; useful if you depend on
|
|
90
|
+
schema specifics that newer layers might change.
|
|
91
|
+
- `1.225.1` is an exact pin.
|
|
92
|
+
|
|
93
|
+
# Examples
|
|
94
|
+
|
|
95
|
+
Runnable scripts live in [teleproto_examples/](teleproto_examples/):
|
|
96
|
+
|
|
97
|
+
- `print_updates.ts` — log every update the client receives
|
|
98
|
+
- `print_messages.ts` — listen for new messages only
|
|
99
|
+
- `replier.ts` — auto-reply pattern for bots and userbots
|
|
100
|
+
- `interactive_terminal.ts` — REPL against a live client
|
|
131
101
|
|
|
132
|
-
|
|
102
|
+
Each is self-contained. Set your credentials at the top and run:
|
|
133
103
|
|
|
134
|
-
-
|
|
135
|
-
- [GitHub Issues](https://github.com/sanyok12345/teleproto/issues) — bug reports and feature requests
|
|
104
|
+
% npx ts-node --transpile-only teleproto_examples/print_updates.ts
|
|
136
105
|
|
|
137
|
-
|
|
106
|
+
# Code contributions
|
|
138
107
|
|
|
139
|
-
|
|
140
|
-
Every donation keeps the lights on and the commits flowing.
|
|
108
|
+
Please see [CONTRIBUTING.md][1].
|
|
141
109
|
|
|
142
|
-
|
|
143
|
-
|---------|---------|
|
|
144
|
-
| **TON** | `sanyok12345.ton` |
|
|
145
|
-
| **TRX** | `TXCtN1UrxST9ovq5tDN3Zb96eNF4164nK5` |
|
|
146
|
-
| **SOL** | `B3XcKmAR9aG2nBiWSMDe76GGa55hPNgLQ92QR2SjRR6F` |
|
|
110
|
+
# License
|
|
147
111
|
|
|
148
|
-
|
|
112
|
+
teleproto is distributed under the [MIT License][2].
|
|
149
113
|
|
|
150
|
-
|
|
114
|
+
[1]: ./CONTRIBUTING.md
|
|
115
|
+
[2]: ./LICENSE
|
package/Version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.225.
|
|
1
|
+
export declare const version = "1.225.2";
|
package/Version.js
CHANGED
package/client/users.js
CHANGED
|
@@ -435,7 +435,7 @@ async function getInputEntity(client, peer) {
|
|
|
435
435
|
}
|
|
436
436
|
throw new Error(`Could not find the input entity for ${JSON.stringify(peer)}.
|
|
437
437
|
Please read https://` +
|
|
438
|
-
"docs.
|
|
438
|
+
"docs.teleproto.dev/concepts/entities to" +
|
|
439
439
|
" find out more details.");
|
|
440
440
|
}
|
|
441
441
|
/** @hidden */
|
|
@@ -14,26 +14,22 @@ export declare class MTProtoState {
|
|
|
14
14
|
private securityChecks;
|
|
15
15
|
/**
|
|
16
16
|
*
|
|
17
|
-
`
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
together all the required information.
|
|
17
|
+
`MTProtoSender` needs to hold a state in order to encrypt and decrypt
|
|
18
|
+
incoming/outgoing messages, as well as generate message IDs. Instances
|
|
19
|
+
of this class hold together all the required information.
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
the concept of "copying" sessions with the unnecessary entities or
|
|
28
|
-
updates state for these connections doesn't make sense.
|
|
21
|
+
A `Session` is intentionally not used here: the sender should *not* be
|
|
22
|
+
concerned with persisting this state to disk. Multiple senders may
|
|
23
|
+
exist for different data centers or CDNs, each requiring its own
|
|
24
|
+
authkey — "copying" a session along with unrelated entities or update
|
|
25
|
+
state would make no sense.
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
authentication process, at which point the `MTProtoPlainSender` is better
|
|
27
|
+
A `MTProtoPlainState` doing no encryption could in principle be used
|
|
28
|
+
through `MTProtoLayer` and remove the need for `MTProtoPlainSender`,
|
|
29
|
+
but `MTProtoLayer` targets efficient throughput and this state class
|
|
30
|
+
is also more advanced (gzipping, invoking after other message IDs).
|
|
31
|
+
Too many helper methods would be needed to make it convenient during
|
|
32
|
+
authentication, where `MTProtoPlainSender` is the better fit.
|
|
37
33
|
* @param authKey
|
|
38
34
|
* @param loggers
|
|
39
35
|
* @param securityChecks
|
package/network/MTProtoState.js
CHANGED
|
@@ -16,26 +16,22 @@ const ReceivedIdsManager_1 = require("./ReceivedIdsManager");
|
|
|
16
16
|
class MTProtoState {
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
19
|
-
`
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
together all the required information.
|
|
19
|
+
`MTProtoSender` needs to hold a state in order to encrypt and decrypt
|
|
20
|
+
incoming/outgoing messages, as well as generate message IDs. Instances
|
|
21
|
+
of this class hold together all the required information.
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
the concept of "copying" sessions with the unnecessary entities or
|
|
30
|
-
updates state for these connections doesn't make sense.
|
|
23
|
+
A `Session` is intentionally not used here: the sender should *not* be
|
|
24
|
+
concerned with persisting this state to disk. Multiple senders may
|
|
25
|
+
exist for different data centers or CDNs, each requiring its own
|
|
26
|
+
authkey — "copying" a session along with unrelated entities or update
|
|
27
|
+
state would make no sense.
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
authentication process, at which point the `MTProtoPlainSender` is better
|
|
29
|
+
A `MTProtoPlainState` doing no encryption could in principle be used
|
|
30
|
+
through `MTProtoLayer` and remove the need for `MTProtoPlainSender`,
|
|
31
|
+
but `MTProtoLayer` targets efficient throughput and this state class
|
|
32
|
+
is also more advanced (gzipping, invoking after other message IDs).
|
|
33
|
+
Too many helper methods would be needed to make it convenient during
|
|
34
|
+
authentication, where `MTProtoPlainSender` is the better fit.
|
|
39
35
|
* @param authKey
|
|
40
36
|
* @param loggers
|
|
41
37
|
* @param securityChecks
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teleproto",
|
|
3
|
-
"version": "1.225.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.225.2",
|
|
4
|
+
"description": "Telegram MTProto API client library written in TypeScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"repository": {
|
|
@@ -15,13 +15,11 @@
|
|
|
15
15
|
"keywords": [
|
|
16
16
|
"telegram",
|
|
17
17
|
"mtproto",
|
|
18
|
-
"
|
|
19
|
-
"client",
|
|
20
|
-
"nodejs",
|
|
18
|
+
"userbot",
|
|
21
19
|
"typescript",
|
|
22
|
-
"
|
|
20
|
+
"nodejs"
|
|
23
21
|
],
|
|
24
|
-
"homepage": "https://
|
|
22
|
+
"homepage": "https://docs.teleproto.dev",
|
|
25
23
|
"dependencies": {
|
|
26
24
|
"async-mutex": "^0.3.0",
|
|
27
25
|
"big-integer": "^1.6.48",
|