opentele2-versions
The current official Telegram client versions, fetched from their public release feeds, plus the
stable Chrome and Firefox versions the web fingerprints use, as a patch onto
opentele2_core::api::Versions.
[dependencies]
opentele2-core = "2.0.0"
opentele2-versions = "2.0.0"The crate uses blocking HTTP (ureq with rustls) and no async runtime; it has no features.
use std::time::Duration;
use opentele2_core::api::{self, Client, Versions};
fn main() {
let patch = opentele2_versions::fetch_all(Duration::from_secs(5));
let mut versions = Versions::offline();
patch.apply(&mut versions);
println!("{}", api::profile(Client::Android, &versions).app_version);
}fetch_all
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
pub const API_USER_AGENT: &str = "opentele2";
pub fn fetch_all(timeout: Duration) -> VersionsPatch;fetch_all queries the nine sources (Telegram Desktop, Android, Telegram X, iOS, macOS, Web K,
Web A, Chrome, Firefox) in parallel, one thread each, and merges whatever answered. timeout
bounds each HTTP request; a source with a fallback makes at most two. It never fails: a source
that errors, times out or returns nothing usable leaves its fields None, and with no network the
patch is empty. API_USER_AGENT is sent to the JSON and plain-text sources, TG_USER_AGENT (a
desktop Chrome user agent) to t.me.
VersionsPatch
pub struct VersionsPatch {
pub desktop_app_version: Option<String>,
pub android_app_version: Option<String>,
pub android_app_version_code: Option<u32>,
pub android_x_app_version: Option<String>,
pub ios_app_version: Option<String>,
pub ios_build_number: Option<u32>,
pub macos_app_version: Option<String>,
pub macos_build_number: Option<u32>,
pub web_k_version: Option<String>,
pub web_a_version: Option<String>,
pub chrome_version: Option<String>,
pub firefox_version: Option<String>,
}
impl VersionsPatch {
pub const FIELDS: &[&str];
pub fn merge(&mut self, other: Self);
pub fn to_map(&self) -> Map<String, Value>;
pub fn from_map(map: &Map<String, Value>) -> Result<Self, String>;
pub fn is_empty(&self) -> bool;
pub fn apply(&self, versions: &mut Versions);
}| Method | Description |
|---|---|
merge(other) | Takes every field other sets, keeping the rest. |
to_map() / from_map(map) | The set fields keyed by field name, and back; an unknown key or a wrongly typed value is an error naming the key. |
is_empty() | Whether no field is set. |
apply(versions) | Writes every set field onto versions, except desktop_app_version, which stays bound to the tdata version; chrome_version goes through Versions::, so the user agent follows it. |
parse
The parsing of every response as pure functions, testable without the network:
parse_tdesktop, parse_telegram_x, parse_android_tgstable, parse_android_play,
parse_ios_tgstable, parse_ios_itunes, parse_macos_brew, parse_macos_itunes, parse_web_k,
parse_web_a, parse_chrome and parse_firefox, each returning Option<VersionsPatch>, and
parse_tgstable for the posts of the tgstable channel.