Skip to Content
Guidestdata to grammers

tdata to grammers

Open the account of a Telegram Desktop tdata folder in grammers  0.11: opentele2-grammers turns the account into grammers SessionData and the API profile into grammers ConnectionParams. With its client feature it also runs the opentele2 flows (QR login, session admin, consistency checks, tdata from a client) over a live grammers Client. grammers is a Rust library; Python and Node use Telethon and mtcute instead.

Warning:

Work on a copy of the folder. grammers’ SessionData and its DcOption print the raw auth key with Debug: never log them, and never share or commit a session file.

Install

grammers is a Rust library. In Python, use Telethon (see tdata to Telethon); in Node, use mtcute (see tdata to mtcute).

Turn the account into SessionData

session_data(account) gives a grammers SessionData: the main DC as home DC, every production DC with its first IPv4 and IPv6 endpoints (the stored config’s when the account has one), the account’s key on the main DC only, and the self user in peer_infos. The updates state is empty, so grammers fetches it on first use.

SessionData is the grammers format. Python and Node build Telethon and mtcute sessions from the same account: telethon_string_session / mtcute_string_session, or telethonStringSession / toStringSession.

Turn the profile into ConnectionParams

connection_params(&profile) copies the profile’s device model, system version, app version, system language code and language code into grammers’ ConnectionParams. The api_id goes to grammers separately, the api_hash at sign-in.

Python's opentele2 TelegramClient takes api=API.TelegramDesktop; Node passes initConnectionOptions(profile) from opentele2/mtcute to mtcute.

Note:

grammers 0.11 builds initConnection itself and always sends an empty lang_pack and no params, and ConnectionParams has no field for either. A grammers session with the desktop profile matches Telegram Desktop’s device, system, app and language fields, but not its lang_pack (tdesktop) or tz_offset. See initConnection fingerprints.

Connect a client

Build a grammers SenderPool over the session with the profile’s api_id and connection params, wrap its handle in a Client and run the pool on the runtime.

Python: TDesktop('tdata').ToTelethon(...) returns an opentele2 TelegramClient ready for connect(). Node: build an mtcute TelegramClient with initConnectionOptions and importSession(toStringSession(...)).

Use the client flows

With the client feature, opentele2_grammers::client runs over anything that implements its Invoker trait, which grammers_client::Client does. Flows that read or change session state also take the grammers Session the pool was built with, because grammers 0.11 keeps the client’s session private.

FlowFunction
Self user idget_me_id(&client)
QR login with 2FAqr_login(&authorized, &new, &*new_session, api_id, &api_hash, password)
Sessionssessions, current_session, terminate_session, terminate_all_sessions, sessions_table, is_official_app
Consistency checksrun_consistency_checks(&client, &expectations)
tdata from a clientaccount_from_client(&client, &*session, index), tdata_from_client(...)

Python runs the same flows as TelegramClient methods (QRLoginToNewClient, GetSessions, PrintSessions, RunConsistencyChecks, ToTDesktop); Node runs them over an mtcute client from opentele2/mtcute (qrLoginToNewClient, getSessions, formatSessions, runConsistencyChecks, tdataFromClient).

Go back from grammers

account_from_session(&data, index) is the inverse of session_data: the home DC key and the self user of a SessionData become a tdata account. The client to tdata guide saves it as a folder, from saved data or from a live client.

Next

Last updated on