telethon 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5607a36bd3fbc7d666e096d87c2e4b27afd11a6094dd7b0543b08f34f3f21b33
4
+ data.tar.gz: 6112f30ab2b1828057dcf93bb4fda8795da297e0024fe9a6301d7d0ae3246aca
5
+ SHA512:
6
+ metadata.gz: 605c58ae8407a5f20d65d9025ed27329280f4893db0f5320a9ca89ce4333161419ab65b3cc58a5c487a939e51964fd1f6e4626e7940f163f0601723d58f3a848
7
+ data.tar.gz: 88ba8e5a1977c16267e18a8ab593e316fe2acd28fdf2d4db4e285d8be1e19ef3d0e1ad885e0657a82ec1a4aaeefa015298596a310dc428582d5ee3a2556ab052
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ - MTProto crypto: AES-256-IGE and CTR, SHA-512 and PBKDF2-HMAC-SHA512, big-integer math on byte
13
+ strings, Pollard-Brent pq factorization, Telegram's RSA keys and the SRP 2FA check. CRuby uses
14
+ openssl and Integer; the Spinel build uses the C in `native/`, checked byte for byte against them.
15
+ - TL: the whole layer-234 schema embedded as data, `TL::Object` values, and a codec for flags, vectors,
16
+ bare types, gzip_packed and typed function results.
17
+ - Network: the obfuscated intermediate transport, the auth-key exchange and a synchronous MTProto 2.0
18
+ sender (salts, clock, acks, containers, gzip, rpc errors). Works against Telegram from CRuby and
19
+ from the native binary.
20
+ - Sessions: `session.json` and `entities.json`, owner-only, and a one-time import from a Telethon
21
+ `.session` (through the sqlite3 command).
22
+ - `Telethon::Client`: connects, creates the auth key, follows *_MIGRATE errors, sleeps through short
23
+ FLOOD_WAITs, and exports the authorization to other data centers. Login by code, 2FA (SRP) and QR.
24
+ - Client methods tg needs: entities (cache, @usernames, the dialog list), message history and forum
25
+ topics, messages by id, send, edit, forward, delete, file upload (albums included) and download.
26
+ - The `tg` command: login, import-session, whoami, topics, export, download, delete, send, edit,
27
+ forward, as tg.py had them. Checked on a real account: `export` writes the same bytes as tg.py, and
28
+ `download` the same files.
29
+ - `Telethon::QR`: a QR encoder for the login URL, module for module the same as Python's qrcode.
30
+ - `rake oracle` and `test/telethon_parity_test.rb`: the port checked byte for byte against Telethon.
data/LICENSE ADDED
@@ -0,0 +1,48 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 shogi-dojo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---------------------------------------------------------------------------
24
+
25
+ telethon.rb is a port of Telethon (https://codeberg.org/Lonami/Telethon),
26
+ whose license follows. data/api.tl and data/mtproto.tl are copied from it.
27
+
28
+ MIT License
29
+
30
+ Copyright (c) 2016-Present LonamiWebs
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining a copy
33
+ of this software and associated documentation files (the "Software"), to deal
34
+ in the Software without restriction, including without limitation the rights
35
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36
+ copies of the Software, and to permit persons to whom the Software is
37
+ furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in all
40
+ copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
48
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # telethon.rb
2
+
3
+ A Ruby port of [Telethon](https://codeberg.org/Lonami/Telethon), the Python MTProto client by
4
+ Lonami, with a `tg` command line. It logs in as a Telegram **user account** (not a bot), so it can
5
+ read chat history and delete messages of any age, which the Bot API can't.
6
+
7
+ It is a port of the parts of Telethon a user-account CLI needs, not all of it. The original, and its
8
+ full documentation, is at <https://codeberg.org/Lonami/Telethon> (docs: <https://docs.telethon.dev>).
9
+
10
+ - Pure Ruby, zero runtime dependencies (the standard library's `openssl`, `socket`, `zlib`, `json`).
11
+ - Also compiles to a standalone native binary with [Spinel](https://github.com/matz/spinel), matz's
12
+ Ruby AOT compiler. The binary links nothing but the system C library.
13
+ - API layer 234, the schema of Telethon v1.46.
14
+
15
+ Status: 0.1.0, unreleased. Checked byte for byte against Telethon (see "Tested against Telethon").
16
+
17
+ ## The `tg` command
18
+
19
+ | Command | What it does |
20
+ |---|---|
21
+ | `tg login [--qr]` | Once, in an interactive terminal: API id/hash, then phone + code or a QR scan, then 2FA |
22
+ | `tg import-session [FILE]` | Once, instead of logging in: take over a Telethon `.session` (default `$TG_HOME/manager.session`) |
23
+ | `tg whoami` | The logged-in account |
24
+ | `tg topics CHAT` | A forum's topics, `id<TAB>title` |
25
+ | `tg export CHAT [--topic ID] [--limit 100 \| --all] [--before ID] [--out FILE]` | History as JSON (owner-only file), with topic links and pagination metadata |
26
+ | `tg download CHAT ID... [--out DIR]` | Saves those messages' attachments into DIR (created owner-only; files are owner-only too) |
27
+ | `tg delete CHAT ID... [--yes]` | Deletes for everyone, after a typed `yes` (or `--yes`) |
28
+ | `tg send CHAT TEXT [--topic ID] [--file PATH ...]` | Posts as the account; with `--file`, sends documents and the text becomes the caption |
29
+ | `tg edit CHAT ID TEXT` | Replaces the text (or caption) of a message the account sent |
30
+ | `tg forward CHAT ID... [--from CHAT] [--delete-source]` | Forwards without the "Forwarded from" header (default source: Saved Messages) |
31
+
32
+ `CHAT` is a numeric id (`-1001874396477`), a `@username`, or `me`. Every command except `login`
33
+ refuses to prompt, so they all work over a non-interactive `ssh`.
34
+
35
+ The session is the whole account: whoever can read it can read every chat and post as the account.
36
+ It lives in `$TG_HOME` (else `$DOJO_TG_HOME`, else `~/.config/tg`), in a directory only its owner can
37
+ read: `config.json` (API id and hash), `session.json` (data center and auth key) and `entities.json`
38
+ (the access hashes of the chats and users seen). Get the API id and hash at <https://my.telegram.org>.
39
+
40
+ These commands, their output and their refusals are those of `tg.py`, the Telethon script this
41
+ replaces; `tg export` writes the same JSON, byte for byte.
42
+
43
+ ## As a library
44
+
45
+ ```ruby
46
+ require "telethon"
47
+
48
+ session = Telethon::Session.new(File.expand_path("~/.config/tg"))
49
+ client = Telethon::Client.new(session, api_id: 12345, api_hash: "...")
50
+ client.connect
51
+ chat = client.get_entity("@telegram")
52
+ client.iter_messages(chat, limit: 10) { |message, sender| puts message["message"] }
53
+ client.disconnect
54
+ ```
55
+
56
+ TL objects are `Telethon::TL::Object`s: a schema name and its fields by their schema names
57
+ (`message["reply_to"]["reply_to_top_id"]`). Any function of the layer can be called with
58
+ `client.call(Telethon::TL.make("messages.getHistory", ...))`.
59
+
60
+ ## Tested against Telethon
61
+
62
+ `rake oracle` runs Telethon itself (the commit the schema comes from) and Python's `qrcode` on fixed
63
+ inputs, and `test/telethon_parity_test.rb` checks the port against what they produced: the bytes of
64
+ every request the client sends, a decoded message, the auth-key exchange, RSA, MTProto 2.0 encryption,
65
+ the SRP 2FA check and the login QR code. `spin test` runs every test natively as well and compares it
66
+ with CRuby.
67
+
68
+ ## Install
69
+
70
+ ```sh
71
+ gem install telethon
72
+ ```
73
+
74
+ Or build the native binary from a checkout (needs Spinel, see [DEVELOPING.md](DEVELOPING.md)):
75
+
76
+ ```sh
77
+ rake build_native # -> build/bin/tg
78
+ rake build_linux # -> build/linux-amd64/tg, for a Debian trixie x86_64 server (needs podman)
79
+ ```
80
+
81
+ ## License
82
+
83
+ MIT, like Telethon. See [LICENSE](LICENSE), which carries Telethon's copyright notice as well as this
84
+ project's, because this is a derived work. `data/api.tl` and `data/mtproto.tl` are Telethon's.