Profiles and devices
The official client API profiles and the device catalogs their generated devices come from.
profiles.mjs
import { generate, profile, profilesEqual } from 'opentele2'
const desktop = profile('TelegramDesktop')
const device = generate('TelegramDesktop', 'account-42', 'windows')
console.log(desktop.apiId, device.deviceModel, device.systemVersion, device.appVersion)
console.log(profilesEqual(device, generate('TelegramDesktop', 'account-42', 'windows'))) // trueApiProfile
index.d.ts
interface ApiProfile {
apiId: number
apiHash: string
deviceModel: string
systemVersion: string
appVersion: string
langCode: string
systemLangCode: string
langPack: string
}The values a client sends in initConnection, with its API id and hash.
Profiles
index.d.ts
function profile(client: 'TelegramDesktop' | 'TelegramAndroid' | 'TelegramAndroidX' | 'TelegramIOS'
| 'TelegramMacOS' | 'TelegramWeb_A' | 'TelegramWeb_K' | 'Webogram',
versions?: Versions | null): ApiProfile
function generate(client: 'TelegramDesktop' | 'TelegramAndroid' | 'TelegramAndroidX' | 'TelegramIOS'
| 'TelegramMacOS' | 'TelegramWeb_A' | 'TelegramWeb_K' | 'Webogram',
seed?: string | number | bigint | null,
system?: 'windows' | 'macos' | 'linux' | null, versions?: Versions | null): ApiProfile
function profilesEqual(a: ApiProfile, b: ApiProfile): boolean
function formatAppVersion(version: number): string
const OFFICIAL_API_IDS: number[]
function isOfficialApiId(apiId: number): boolean| Function | Description |
|---|---|
profile( | The default profile of client, with versions overriding the offline PlatformVersions fields. |
generate( | The profile API.<client>.Generate returns: a device picked for seed (a string, or an integer number or bigint as its decimal text), random without one. system applies to TelegramDesktop only; web clients get a browser user agent from the web catalog. |
profilesEqual(a, b) | Whether apiId, apiHash, deviceModel, systemVersion and appVersion match; the language fields are not compared. |
format | A packed Telegram Desktop version as major.minor.patch without a zero patch: 7003001 is "7.3.1", 7003000 is "7.3". |
OFFICIAL_API_IDS, isOfficialApiId(apiId) | The api_id of every official profile, and whether apiId is one. |
Session JSON
index.d.ts
function profileFromSessionJson(json: string | Record<string, unknown>): ApiProfile
function profileToSessionJson(profile: ApiProfile, extra?: Record<string, unknown> | null): Record<string, unknown>
function sessionJsonFields(): Array<SessionJsonField>
function defaultExtraFields(): Array<[string, string | boolean | null]>
interface SessionJsonField {
key: string
attribute: string
default: string | null
fallback: string | null
}| Function | Description |
|---|---|
profile | The profile APIData.from_json reads from session JSON text or a parsed object; app_id, app_hash, device, sdk and app_version are required, system_lang_code falls back to system_lang_pack, then "en". Malformed JSON or fields throw OT_IO. |
profile | The session JSON APIData.to_json(extra) writes: the profile keys, then the 19 account keys with their defaults, with extra overriding and appending. |
sessionJsonFields() | The nine profile keys in write order, each with its attribute, default and fallback key. |
defaultExtraFields() | The account keys written after the profile keys, as [key, default] pairs. |
Device catalogs
index.d.ts
function catalogEntries(platform: 'windows' | 'linux' | 'macos' | 'android' | 'ios' | 'web_a' | 'web_k'): Array<CatalogEntry>
function deviceModels(platform: 'windows' | 'linux' | 'macos' | 'android' | 'ios' | 'web_a' | 'web_k'): Array<string>
function systemVersions(platform: 'windows' | 'linux' | 'macos' | 'android' | 'ios' | 'web_a' | 'web_k'): Array<string>
function webBrowserWeights(): Record<string, number>
interface CatalogEntry {
model: string
systemVersion: string
weight: number
}| Function | Description |
|---|---|
catalog | The weighted device pairs of a catalog; the weight is how many times the expanded deviceList repeats the pair. Mac versions are bare. |
deviceModels(platform) | The catalog’s models in file order (empty for Android). |
system | The catalog’s system versions in file order: SDK 29 to SDK 37 for Android, the clients’ platform strings for the web. |
webBrowserWeights() | The browser weights of the web device pool: chrome 19, edge 2, firefox 1. |
Last updated on