tgdata 0.1.3__tar.gz → 0.1.5__tar.gz
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.
- {tgdata-0.1.3 → tgdata-0.1.5}/PKG-INFO +90 -1
- {tgdata-0.1.3 → tgdata-0.1.5}/README.md +89 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/__init__.py +3 -2
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/connection_engine.py +69 -5
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/login.py +5 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/models.py +5 -1
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_42_album_assembly.py +1 -1
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_43_photo_trails.py +1 -1
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_45_group_profile.py +1 -1
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_46_group_activity.py +1 -1
- tgdata-0.1.5/tgdata/smoke_tests/test_49_worker_media.py +368 -0
- tgdata-0.1.5/tgdata/smoke_tests/test_50_websocket_transport.py +1114 -0
- tgdata-0.1.5/tgdata/websocket_transport.py +92 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/worker.py +9 -4
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/worker_engine.py +24 -1
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/worker_protocol.py +11 -5
- tgdata-0.1.5/tgdata/ws_stream.py +208 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata.egg-info/PKG-INFO +90 -1
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata.egg-info/SOURCES.txt +4 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/setup.cfg +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/setup.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/_terminal_input.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/account_operation.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/account_pool.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/album.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/backfill.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/backfill_engine.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/backfill_state.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/batch_engine.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/batch_files.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/batch_heartbeat.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/budget_client.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/discovery_engine.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/group_activity.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/group_operations.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/group_profile.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/health.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/history_window.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/join_budget.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/join_client.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/login_cli.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/login_file.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/message_batch.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/message_engine.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/owned_health.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/photo_trails.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/pool_lifecycle.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/pool_observation.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/pool_result.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/pool_source.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/pool_state.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/progress.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/progress_facade.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/read_budget.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/session_store.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/__init__.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/_terminal_login_framing.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/_terminal_login_handoffs.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/_terminal_login_modes.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/_terminal_login_observer.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/my_test.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/pool_storage_cases.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_00_connection.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_01_list_group_chats.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_02_get_message_count.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_03_get_all_messages.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_04_get_all_messages_in_batches.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_05_with_progress_feature.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_06_polling_simple.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_07_on_new_message_simple.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_07_real_time_event_handler.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_08_batch_callback.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_08_polling.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_10_advanced_features.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_11_discover_groups.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_12_proxy.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_13_device_identity.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_14_flood_threshold.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_15_login_checks.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_16_health_events.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_17_session_store.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_18_read_budget.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_19_message_batches.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_22_daily_continuation.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_23_fixed_windows.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_24_backfill_state.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_25_backfill_delivery.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_26_backfill_completion.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_27_backfill_pacing.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_28_backfill_controls.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_29_backfill_public.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_30_backfill_integration.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_31_account_pool.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_32_account_operation.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_33_owned_health.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_34_group_access.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_35_join_budget.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_36_group_join.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_37_worker.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_38_worker_process.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_39_pool_lifecycle.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_40_pool_outcomes.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_41_stepwise_login.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_44_batch_heartbeat.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_48_terminal_login.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_debug_min_id.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_polling_debug.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/smoke_tests/test_username_support.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/sync_engine.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/sync_store.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/tgdata.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata/utils.py +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata.egg-info/dependency_links.txt +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata.egg-info/entry_points.txt +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata.egg-info/requires.txt +0 -0
- {tgdata-0.1.3 → tgdata-0.1.5}/tgdata.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tgdata
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: A production-grade Python library for extracting and processing Telegram group and channel messages
|
|
5
5
|
Author: enes kuzucu
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -300,6 +300,95 @@ require_proxy = true
|
|
|
300
300
|
- An existing session keeps working through a proxy; a session file is not
|
|
301
301
|
tied to an IP.
|
|
302
302
|
|
|
303
|
+
### Connecting through Telegram's WebSocket door (optional)
|
|
304
|
+
|
|
305
|
+
By default, tgdata (through Telethon) connects to each Telegram data centre by
|
|
306
|
+
**IP address**. Some proxies send a connection out from an account's assigned
|
|
307
|
+
exit address only when the target is a **hostname**. For those, set the account's
|
|
308
|
+
network transport to Telegram's WebSocket door, which is reached by name:
|
|
309
|
+
|
|
310
|
+
```ini
|
|
311
|
+
[Telegram]
|
|
312
|
+
api_id = 1234566
|
|
313
|
+
api_hash = a24adjfakjdfakjshdflkajsbdflk
|
|
314
|
+
session_file = /absolute/path/to/my_session
|
|
315
|
+
proxy = http://user:password@proxy.example:8080
|
|
316
|
+
transport = websocket
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
**How it connects.**
|
|
320
|
+
- Every connection the account opens goes to
|
|
321
|
+
`wss://<name>.web.telegram.org/apiws`: login, reads, downloads from other data
|
|
322
|
+
centres, owned operations, the account pool, the worker, and every reconnect.
|
|
323
|
+
- The names are `pluto`, `venus`, `aurora`, `vesta` and `flora` (`.web.telegram.org`),
|
|
324
|
+
for data centres 1–5. They are chosen when each connection is built.
|
|
325
|
+
- **Never an IP, and no fallback.** A data centre with no known name is an error,
|
|
326
|
+
never a guess, and nothing falls back to the ordinary connection.
|
|
327
|
+
|
|
328
|
+
**What the proxy must allow:** a tunnel to `*.web.telegram.org:443`, by HTTP CONNECT
|
|
329
|
+
or SOCKS. tgdata always asks the proxy to resolve names (SOCKS4 is sent as
|
|
330
|
+
SOCKS4a). `pip install 'tgdata[proxy]'` is needed for every proxy kind, `http://`
|
|
331
|
+
included.
|
|
332
|
+
|
|
333
|
+
**Inside the tunnel:**
|
|
334
|
+
- TLS to the hostname, with the certificate verified against the system's trust
|
|
335
|
+
store;
|
|
336
|
+
- a WebSocket upgrade, `GET /apiws` with `Sec-WebSocket-Protocol: binary` and no
|
|
337
|
+
`Origin` header;
|
|
338
|
+
- Telethon's own obfuscated transport, carried in binary frames.
|
|
339
|
+
|
|
340
|
+
**What stays as it is:**
|
|
341
|
+
- session files, the device identity, and every other setting;
|
|
342
|
+
- `require_proxy`. With no proxy, the transport connects directly, by name, from
|
|
343
|
+
the machine's own address.
|
|
344
|
+
- The default is `transport = tcp`, exactly the behaviour before this option
|
|
345
|
+
existed.
|
|
346
|
+
|
|
347
|
+
**Failures:**
|
|
348
|
+
- **`tgdata.TransportConfigError`** stops at once: it is never retried when
|
|
349
|
+
connecting. After a dropped connection, Telethon's own reconnect loop may try a
|
|
350
|
+
few times, logging each attempt, before giving up. It covers an
|
|
351
|
+
unknown `transport` value, a data centre with no WebSocket name, and a certificate
|
|
352
|
+
that does not verify (a proxy that intercepts TLS, or a missing trust store). It is
|
|
353
|
+
a `ProxyConfigError`, so polling stops on it, the worker reports a
|
|
354
|
+
`configuration_error`, and the account pool stops the account.
|
|
355
|
+
- **Anything else** — a refused upgrade, a reset, the door closing the connection —
|
|
356
|
+
is a `ConnectionError`, retried like any network failure.
|
|
357
|
+
- **Discovery** waits out connect errors until its `max_offline` limit, as it does for
|
|
358
|
+
any connection error.
|
|
359
|
+
|
|
360
|
+
**Confirming it is active:**
|
|
361
|
+
- the engine logs once "…, over Telegram's WebSocket transport by hostname";
|
|
362
|
+
- `health_check()['transport']` is `'websocket'`;
|
|
363
|
+
- with Telethon's INFO logging on, every connection appears as
|
|
364
|
+
`Connecting to vesta.web.telegram.org:443/WebSocket...`. That line never shows
|
|
365
|
+
an IP.
|
|
366
|
+
|
|
367
|
+
**Expect reconnects.** Connections through the door have been seen cut every few
|
|
368
|
+
minutes, even with Telethon's keep-alive pings running.
|
|
369
|
+
- An ordinary `TgData` client reconnects on its own, by name.
|
|
370
|
+
- Strict clients never reconnect in the middle of an operation: owned operations,
|
|
371
|
+
`AccountPool` sources and the stepwise login. A request after a cut fails as a
|
|
372
|
+
retryable transport error, and the client reconnects on its next use. A pool
|
|
373
|
+
account takes a `transport` outcome and the 30 s default cooldown.
|
|
374
|
+
|
|
375
|
+
**Verified on Telethon 1.45.0.** The transport relies on Telethon's connection
|
|
376
|
+
internals. After any Telethon upgrade, run the canary:
|
|
377
|
+
`python -m tgdata.smoke_tests.test_50_websocket_transport`.
|
|
378
|
+
|
|
379
|
+
**Risks to accept:**
|
|
380
|
+
- **The names are not published by Telegram,** and could change. A renamed endpoint
|
|
381
|
+
looks exactly like an outage: every attempt fails at the proxy's name lookup.
|
|
382
|
+
- **Telegram's treatment of an account** whose earlier sessions came from a desktop
|
|
383
|
+
app, and which now arrives through the web transport, is not documented.
|
|
384
|
+
- **The web relays may have rate limits of their own.**
|
|
385
|
+
- **A login key made over the ordinary connection** worked over the door in a live
|
|
386
|
+
check (2026-11-26). Keys belong to a data centre, not to a transport.
|
|
387
|
+
- **A policy refusal could look like an account problem.** If Telegram ever refuses
|
|
388
|
+
the web transport with an error on the first request, the health events could
|
|
389
|
+
report it as `unclassified`. Compare against `transport = tcp` before reading it as
|
|
390
|
+
an account verdict.
|
|
391
|
+
|
|
303
392
|
### A fixed device identity (optional)
|
|
304
393
|
|
|
305
394
|
Every connection tells Telegram what device it is running on — a device
|
|
@@ -271,6 +271,95 @@ require_proxy = true
|
|
|
271
271
|
- An existing session keeps working through a proxy; a session file is not
|
|
272
272
|
tied to an IP.
|
|
273
273
|
|
|
274
|
+
### Connecting through Telegram's WebSocket door (optional)
|
|
275
|
+
|
|
276
|
+
By default, tgdata (through Telethon) connects to each Telegram data centre by
|
|
277
|
+
**IP address**. Some proxies send a connection out from an account's assigned
|
|
278
|
+
exit address only when the target is a **hostname**. For those, set the account's
|
|
279
|
+
network transport to Telegram's WebSocket door, which is reached by name:
|
|
280
|
+
|
|
281
|
+
```ini
|
|
282
|
+
[Telegram]
|
|
283
|
+
api_id = 1234566
|
|
284
|
+
api_hash = a24adjfakjdfakjshdflkajsbdflk
|
|
285
|
+
session_file = /absolute/path/to/my_session
|
|
286
|
+
proxy = http://user:password@proxy.example:8080
|
|
287
|
+
transport = websocket
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**How it connects.**
|
|
291
|
+
- Every connection the account opens goes to
|
|
292
|
+
`wss://<name>.web.telegram.org/apiws`: login, reads, downloads from other data
|
|
293
|
+
centres, owned operations, the account pool, the worker, and every reconnect.
|
|
294
|
+
- The names are `pluto`, `venus`, `aurora`, `vesta` and `flora` (`.web.telegram.org`),
|
|
295
|
+
for data centres 1–5. They are chosen when each connection is built.
|
|
296
|
+
- **Never an IP, and no fallback.** A data centre with no known name is an error,
|
|
297
|
+
never a guess, and nothing falls back to the ordinary connection.
|
|
298
|
+
|
|
299
|
+
**What the proxy must allow:** a tunnel to `*.web.telegram.org:443`, by HTTP CONNECT
|
|
300
|
+
or SOCKS. tgdata always asks the proxy to resolve names (SOCKS4 is sent as
|
|
301
|
+
SOCKS4a). `pip install 'tgdata[proxy]'` is needed for every proxy kind, `http://`
|
|
302
|
+
included.
|
|
303
|
+
|
|
304
|
+
**Inside the tunnel:**
|
|
305
|
+
- TLS to the hostname, with the certificate verified against the system's trust
|
|
306
|
+
store;
|
|
307
|
+
- a WebSocket upgrade, `GET /apiws` with `Sec-WebSocket-Protocol: binary` and no
|
|
308
|
+
`Origin` header;
|
|
309
|
+
- Telethon's own obfuscated transport, carried in binary frames.
|
|
310
|
+
|
|
311
|
+
**What stays as it is:**
|
|
312
|
+
- session files, the device identity, and every other setting;
|
|
313
|
+
- `require_proxy`. With no proxy, the transport connects directly, by name, from
|
|
314
|
+
the machine's own address.
|
|
315
|
+
- The default is `transport = tcp`, exactly the behaviour before this option
|
|
316
|
+
existed.
|
|
317
|
+
|
|
318
|
+
**Failures:**
|
|
319
|
+
- **`tgdata.TransportConfigError`** stops at once: it is never retried when
|
|
320
|
+
connecting. After a dropped connection, Telethon's own reconnect loop may try a
|
|
321
|
+
few times, logging each attempt, before giving up. It covers an
|
|
322
|
+
unknown `transport` value, a data centre with no WebSocket name, and a certificate
|
|
323
|
+
that does not verify (a proxy that intercepts TLS, or a missing trust store). It is
|
|
324
|
+
a `ProxyConfigError`, so polling stops on it, the worker reports a
|
|
325
|
+
`configuration_error`, and the account pool stops the account.
|
|
326
|
+
- **Anything else** — a refused upgrade, a reset, the door closing the connection —
|
|
327
|
+
is a `ConnectionError`, retried like any network failure.
|
|
328
|
+
- **Discovery** waits out connect errors until its `max_offline` limit, as it does for
|
|
329
|
+
any connection error.
|
|
330
|
+
|
|
331
|
+
**Confirming it is active:**
|
|
332
|
+
- the engine logs once "…, over Telegram's WebSocket transport by hostname";
|
|
333
|
+
- `health_check()['transport']` is `'websocket'`;
|
|
334
|
+
- with Telethon's INFO logging on, every connection appears as
|
|
335
|
+
`Connecting to vesta.web.telegram.org:443/WebSocket...`. That line never shows
|
|
336
|
+
an IP.
|
|
337
|
+
|
|
338
|
+
**Expect reconnects.** Connections through the door have been seen cut every few
|
|
339
|
+
minutes, even with Telethon's keep-alive pings running.
|
|
340
|
+
- An ordinary `TgData` client reconnects on its own, by name.
|
|
341
|
+
- Strict clients never reconnect in the middle of an operation: owned operations,
|
|
342
|
+
`AccountPool` sources and the stepwise login. A request after a cut fails as a
|
|
343
|
+
retryable transport error, and the client reconnects on its next use. A pool
|
|
344
|
+
account takes a `transport` outcome and the 30 s default cooldown.
|
|
345
|
+
|
|
346
|
+
**Verified on Telethon 1.45.0.** The transport relies on Telethon's connection
|
|
347
|
+
internals. After any Telethon upgrade, run the canary:
|
|
348
|
+
`python -m tgdata.smoke_tests.test_50_websocket_transport`.
|
|
349
|
+
|
|
350
|
+
**Risks to accept:**
|
|
351
|
+
- **The names are not published by Telegram,** and could change. A renamed endpoint
|
|
352
|
+
looks exactly like an outage: every attempt fails at the proxy's name lookup.
|
|
353
|
+
- **Telegram's treatment of an account** whose earlier sessions came from a desktop
|
|
354
|
+
app, and which now arrives through the web transport, is not documented.
|
|
355
|
+
- **The web relays may have rate limits of their own.**
|
|
356
|
+
- **A login key made over the ordinary connection** worked over the door in a live
|
|
357
|
+
check (2026-11-26). Keys belong to a data centre, not to a transport.
|
|
358
|
+
- **A policy refusal could look like an account problem.** If Telegram ever refuses
|
|
359
|
+
the web transport with an error on the first request, the health events could
|
|
360
|
+
report it as `unclassified`. Compare against `transport = tcp` before reading it as
|
|
361
|
+
an account verdict.
|
|
362
|
+
|
|
274
363
|
### A fixed device identity (optional)
|
|
275
364
|
|
|
276
365
|
Every connection tells Telegram what device it is running on — a device
|
|
@@ -24,7 +24,7 @@ from .group_operations import (
|
|
|
24
24
|
)
|
|
25
25
|
from .group_profile import GroupProfile, GroupPinnedMessage
|
|
26
26
|
from .group_activity import GroupActivity, ActivityMessage
|
|
27
|
-
from .connection_engine import AuthRequiredError, ProxyConfigError
|
|
27
|
+
from .connection_engine import AuthRequiredError, ProxyConfigError, TransportConfigError
|
|
28
28
|
from .login import LoginFlow, LoginStatus, LoginError
|
|
29
29
|
from .discovery_engine import DiscoveryInterrupted
|
|
30
30
|
from .message_batch import MessageBatch, BatchFormatError
|
|
@@ -74,7 +74,7 @@ from .utils import (
|
|
|
74
74
|
# Progress tracking
|
|
75
75
|
from .progress import ProgressTracker
|
|
76
76
|
|
|
77
|
-
__version__ = "0.1.
|
|
77
|
+
__version__ = "0.1.5"
|
|
78
78
|
|
|
79
79
|
__all__ = [
|
|
80
80
|
# Explicit account onboarding
|
|
@@ -122,6 +122,7 @@ __all__ = [
|
|
|
122
122
|
"GroupResponseError",
|
|
123
123
|
"AuthRequiredError",
|
|
124
124
|
"ProxyConfigError",
|
|
125
|
+
"TransportConfigError",
|
|
125
126
|
"DiscoveryInterrupted",
|
|
126
127
|
"MessageBatch",
|
|
127
128
|
"BatchFormatError",
|
|
@@ -147,11 +147,31 @@ class ProxyConfigError(ValueError):
|
|
|
147
147
|
installed, or require_proxy set with no proxy configured.
|
|
148
148
|
|
|
149
149
|
Raised while reading the config — before any connection is opened — so a
|
|
150
|
-
broken proxy setting can never turn into a direct connection.
|
|
150
|
+
broken proxy setting can never turn into a direct connection. (Its
|
|
151
|
+
subclass TransportConfigError can also be raised when a connection is
|
|
152
|
+
built or opened.)"""
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class TransportConfigError(ProxyConfigError):
|
|
156
|
+
"""The WebSocket transport (`transport = websocket`) cannot be used as
|
|
157
|
+
configured or reached: an unknown `transport` value (raised while reading
|
|
158
|
+
the config), a data centre with no WebSocket host (when a connection is
|
|
159
|
+
built), or a certificate that does not verify (when it connects — a proxy
|
|
160
|
+
that intercepts TLS, or a missing trust store). Never retried when
|
|
161
|
+
connecting; after a dropped connection, Telethon's own reconnect loop may
|
|
162
|
+
try a few times, logging each attempt, before it gives up.
|
|
163
|
+
|
|
164
|
+
A ProxyConfigError, so every check for "the configured route to Telegram
|
|
165
|
+
cannot be used" covers it: polling stops, the worker reports a
|
|
166
|
+
configuration_error, and the account pool stops the account (ValueError)."""
|
|
151
167
|
|
|
152
168
|
|
|
153
169
|
# URL scheme -> Telethon proxy type. 'socks5h' / 'socks4a' are accepted as
|
|
154
|
-
# spellings
|
|
170
|
+
# spellings of the same thing: tgdata always asks the proxy to resolve names
|
|
171
|
+
# (rdns), which is what carries the WebSocket transport's hostname
|
|
172
|
+
# (transport = websocket) to the proxy — the account's machine never resolves
|
|
173
|
+
# it. Under the default TCP transport Telegram is addressed by IP, so it is
|
|
174
|
+
# unused there.
|
|
155
175
|
_PROXY_SCHEMES = {'socks5': 'socks5', 'socks5h': 'socks5',
|
|
156
176
|
'socks4': 'socks4', 'socks4a': 'socks4',
|
|
157
177
|
'http': 'http'}
|
|
@@ -173,6 +193,10 @@ def parse_proxy_url(url: str) -> Tuple[Dict[str, Any], str]:
|
|
|
173
193
|
(tg://proxy?..., t.me/proxy?...) are a different protocol and are not
|
|
174
194
|
supported.
|
|
175
195
|
|
|
196
|
+
The dict always asks the proxy to resolve names (rdns): SOCKS5 sends the
|
|
197
|
+
hostname, SOCKS4 sends it as SOCKS4a, and HTTP CONNECT always does. The
|
|
198
|
+
WebSocket transport relies on this to reach Telegram by name.
|
|
199
|
+
|
|
176
200
|
Returns:
|
|
177
201
|
(proxy_dict, display) — display has the password replaced by '***'.
|
|
178
202
|
|
|
@@ -453,6 +477,21 @@ class ConnectionEngine:
|
|
|
453
477
|
f"require_proxy is set in {self.config_path} but no proxy is configured — "
|
|
454
478
|
f"refusing to connect to Telegram directly")
|
|
455
479
|
|
|
480
|
+
# How connections reach Telegram (optional). No `transport` key = 'tcp',
|
|
481
|
+
# Telethon's default, exactly as before. 'websocket' = Telegram's
|
|
482
|
+
# WebSocket door by hostname, never an IP (websocket_transport.py).
|
|
483
|
+
# Independent of the proxy: with no proxy it connects directly by name,
|
|
484
|
+
# and require_proxy keeps its meaning. Read raw, first token, like the
|
|
485
|
+
# proxy keys.
|
|
486
|
+
raw_transport = _first_token(section.get('transport', raw=True)).lower()
|
|
487
|
+
if raw_transport in ('', 'tcp'):
|
|
488
|
+
transport = 'tcp'
|
|
489
|
+
elif raw_transport == 'websocket':
|
|
490
|
+
transport = 'websocket'
|
|
491
|
+
else:
|
|
492
|
+
raise TransportConfigError(
|
|
493
|
+
f"transport = {raw_transport!r} in {self.config_path} — use tcp or websocket")
|
|
494
|
+
|
|
456
495
|
# The account's device identity (optional): what every connection tells
|
|
457
496
|
# Telegram it is running on. With no keys, Telethon derives it from the
|
|
458
497
|
# machine (CPU type, OS release) and from its own version, so the same
|
|
@@ -492,7 +531,8 @@ class ConnectionEngine:
|
|
|
492
531
|
proxy=proxy,
|
|
493
532
|
proxy_display=proxy_display,
|
|
494
533
|
require_proxy=require_proxy,
|
|
495
|
-
**identity
|
|
534
|
+
**identity,
|
|
535
|
+
transport=transport,
|
|
496
536
|
)
|
|
497
537
|
|
|
498
538
|
return self._config
|
|
@@ -551,6 +591,12 @@ class ConnectionEngine:
|
|
|
551
591
|
The config is read first, so a ProxyConfigError (bad URL, missing
|
|
552
592
|
library, require_proxy without a proxy) stops before any socket opens.
|
|
553
593
|
|
|
594
|
+
With `transport = websocket` the client carries ConnectionWebSocket
|
|
595
|
+
(websocket_transport.py): every connection it opens — reconnects and
|
|
596
|
+
other data centres included — reaches Telegram's WebSocket door by
|
|
597
|
+
hostname, never by IP, through the proxy when one is configured.
|
|
598
|
+
Without the key nothing changes: no `connection=` argument is passed.
|
|
599
|
+
|
|
554
600
|
Every client also carries the account's pinned device identity, if the
|
|
555
601
|
config sets one; unpinned fields keep Telethon's machine defaults.
|
|
556
602
|
|
|
@@ -575,10 +621,12 @@ class ConnectionEngine:
|
|
|
575
621
|
config = self._load_config()
|
|
576
622
|
identity = self._identity_kwargs(config)
|
|
577
623
|
if not self._route_logged:
|
|
624
|
+
over = (", over Telegram's WebSocket transport by hostname"
|
|
625
|
+
if config.transport == 'websocket' else "")
|
|
578
626
|
if config.proxy:
|
|
579
|
-
logger.info(f"Telegram connections go via proxy {config.proxy_display}")
|
|
627
|
+
logger.info(f"Telegram connections go via proxy {config.proxy_display}{over}")
|
|
580
628
|
else:
|
|
581
|
-
logger.info("Telegram connections are direct (no proxy configured)")
|
|
629
|
+
logger.info(f"Telegram connections are direct (no proxy configured){over}")
|
|
582
630
|
if identity:
|
|
583
631
|
logger.info("Device identity pinned: " +
|
|
584
632
|
", ".join(f"{key}={value!r}" for key, value in identity.items()))
|
|
@@ -587,6 +635,11 @@ class ConnectionEngine:
|
|
|
587
635
|
self._route_logged = True
|
|
588
636
|
# TelegramClient is looked up here, at call time, so a test that stands
|
|
589
637
|
# in for it (test_13) still controls what is built.
|
|
638
|
+
if config.transport == 'websocket':
|
|
639
|
+
# Imported only for accounts that chose it: a TCP account never
|
|
640
|
+
# loads the module, so nothing in it can affect one.
|
|
641
|
+
from .websocket_transport import ConnectionWebSocket
|
|
642
|
+
client_options = dict(client_options, connection=ConnectionWebSocket)
|
|
590
643
|
name = session_file or config.session_file
|
|
591
644
|
session = StoredSession(self.session_store, name) if self.session_store is not None else name
|
|
592
645
|
client = _client_class(_client_base or TelegramClient)(
|
|
@@ -814,6 +867,13 @@ class ConnectionEngine:
|
|
|
814
867
|
logger.error(f"Authentication failed: {e}")
|
|
815
868
|
raise
|
|
816
869
|
|
|
870
|
+
except ProxyConfigError as e:
|
|
871
|
+
# The configured route cannot be used (e.g. the WebSocket
|
|
872
|
+
# transport's TransportConfigError): keep the type, so callers
|
|
873
|
+
# stop instead of retrying a ConnectionError.
|
|
874
|
+
logger.error(f"Authentication failed: {e}")
|
|
875
|
+
raise
|
|
876
|
+
|
|
817
877
|
except Exception as e:
|
|
818
878
|
logger.error(f"Authentication failed: {e}")
|
|
819
879
|
raise ConnectionError(f"Failed to authenticate: {e}")
|
|
@@ -910,6 +970,9 @@ class ConnectionEngine:
|
|
|
910
970
|
self._pool.mark_rate_limited(client, wait_time)
|
|
911
971
|
await heartbeat_sleep(wait_time)
|
|
912
972
|
await client.connect()
|
|
973
|
+
except ProxyConfigError as e:
|
|
974
|
+
logger.error(f"Connection failed: {e}")
|
|
975
|
+
raise # the route cannot be used: keep the type
|
|
913
976
|
except Exception as e:
|
|
914
977
|
logger.error(f"Connection failed: {e}")
|
|
915
978
|
raise ConnectionError(f"Failed to connect: {e}")
|
|
@@ -933,6 +996,7 @@ class ConnectionEngine:
|
|
|
933
996
|
'primary_connection': False,
|
|
934
997
|
'pool_connections': [],
|
|
935
998
|
'proxy': self._config.proxy_display if self._config else None, # masked; None = direct
|
|
999
|
+
'transport': self._config.transport if self._config else None, # 'tcp' or 'websocket'
|
|
936
1000
|
'device_identity': None, # what connections present; filled below once the config is read
|
|
937
1001
|
'errors': []
|
|
938
1002
|
}
|
|
@@ -156,6 +156,11 @@ class LoginFlow:
|
|
|
156
156
|
settings = dict(api_id=int(config.api_id), api_hash=config.api_hash,
|
|
157
157
|
proxy=config.proxy, require_proxy=config.require_proxy,
|
|
158
158
|
identity=self._engine._identity_kwargs(config))
|
|
159
|
+
if config.transport != 'tcp':
|
|
160
|
+
# Bound like the proxy: it changes where the conversation leaves
|
|
161
|
+
# from. Present only when not the default, so every TCP
|
|
162
|
+
# checkpoint keeps the exact hash it had before (#67).
|
|
163
|
+
settings['transport'] = config.transport
|
|
159
164
|
self._binding = hashlib.sha256(json.dumps(
|
|
160
165
|
settings, sort_keys=True, separators=(',', ':')).encode()).hexdigest()
|
|
161
166
|
self._session = StoredSession(_MemoryStore(), 'login')
|
|
@@ -121,4 +121,8 @@ class ConnectionConfig:
|
|
|
121
121
|
system_version: Optional[str] = None
|
|
122
122
|
app_version: Optional[str] = None
|
|
123
123
|
lang_code: Optional[str] = None
|
|
124
|
-
system_lang_code: Optional[str] = None
|
|
124
|
+
system_lang_code: Optional[str] = None
|
|
125
|
+
# How connections reach Telegram: 'tcp' (Telethon's default, by IP — the
|
|
126
|
+
# behaviour before #67) or 'websocket' (Telegram's WebSocket door, by
|
|
127
|
+
# hostname only). Kept last so positional construction stays valid.
|
|
128
|
+
transport: str = 'tcp'
|
|
@@ -124,7 +124,7 @@ class AlbumTests(unittest.TestCase):
|
|
|
124
124
|
for name in ('TelegramPost', 'AlbumAssemblyError', 'album_post_ids', 'assemble_albums'):
|
|
125
125
|
self.assertIs(getattr(tgdata, name), globals()[name])
|
|
126
126
|
self.assertIn(name, tgdata.__all__)
|
|
127
|
-
self.assertEqual(tgdata.__version__, '0.1.
|
|
127
|
+
self.assertEqual(tgdata.__version__, '0.1.5')
|
|
128
128
|
|
|
129
129
|
def test_sdk_large_ids_captions_and_cross_chat(self):
|
|
130
130
|
rows = (record(1, 'first'), record(2, 'second'))
|
|
@@ -123,7 +123,7 @@ class PhotoTrailTests(unittest.TestCase):
|
|
|
123
123
|
self.assertEqual(member_groups(result), ((1,), (2,)))
|
|
124
124
|
self.assertFalse(result.policy.enabled)
|
|
125
125
|
self.assertEqual((result.folded_posts,result.folded_photos),(0,0))
|
|
126
|
-
self.assertEqual(tgdata.__version__, '0.1.
|
|
126
|
+
self.assertEqual(tgdata.__version__, '0.1.5')
|
|
127
127
|
|
|
128
128
|
def test_policy_validation_and_immutable_roundtrip(self):
|
|
129
129
|
self.assertEqual(PhotoTrailPolicy.from_dict(ON.to_dict()), ON)
|
|
@@ -78,7 +78,7 @@ async def test_defaults_and_full_metadata():
|
|
|
78
78
|
async def test_public_exports_and_detached_immutable_values():
|
|
79
79
|
import tgdata
|
|
80
80
|
assert {'GroupProfile', 'GroupPinnedMessage'} <= set(tgdata.__all__)
|
|
81
|
-
assert tgdata.__version__ == '0.1.
|
|
81
|
+
assert tgdata.__version__ == '0.1.5'
|
|
82
82
|
assert len(tgdata.__all__) == len(set(tgdata.__all__))
|
|
83
83
|
tg, _ = setup(pin_response=pins([message()]))
|
|
84
84
|
value = await profile(tg, 3)
|
|
@@ -76,7 +76,7 @@ async def test_exports_frozen_values_and_json():
|
|
|
76
76
|
assert isinstance(value, GroupActivity) and isinstance(value.messages[0], ActivityMessage)
|
|
77
77
|
assert value.schema_version == 1 and value.account_id == 222
|
|
78
78
|
assert {'GroupActivity', 'ActivityMessage'} <= set(tgdata.__all__)
|
|
79
|
-
assert tgdata.__version__ == '0.1.
|
|
79
|
+
assert tgdata.__version__ == '0.1.5' and len(set(tgdata.__all__)) == len(tgdata.__all__)
|
|
80
80
|
for obj, key in ((value, 'coverage_complete'), (value.messages[0], 'views'), (value.group, 'title')):
|
|
81
81
|
fx.refuses(FrozenInstanceError, lambda: setattr(obj, key, 42))
|
|
82
82
|
data = value.to_dict()
|