Skip to Content
ReferencePythonopentele2.consistency

opentele2.consistency

Server-side checks of a connected TelegramClient: seven requests an official client makes, whose answers tell whether the session looks like the client it claims to be. Every detail line, summary and pass rule comes from the core.

from opentele2.consistency import CheckResult, ConsistencyChecker, ConsistencyReport

TelegramClient.RunConsistencyChecks(auto_warn=True) is the short form of ConsistencyChecker(client, auto_warn=auto_warn).run_all().

ConsistencyChecker

opentele2/consistency.py
class ConsistencyChecker: def __init__(self, client: TelegramClient, *, auto_warn: bool = True) -> None: ... async def run_all(self) -> ConsistencyReport: ... async def check_get_config(self) -> CheckResult: ... async def check_nearest_dc(self) -> CheckResult: ... async def check_current_session(self) -> CheckResult: ... async def check_layer_match(self) -> CheckResult: ... async def check_lang_pack(self) -> CheckResult: ... async def check_app_update(self) -> CheckResult: ... async def check_terms_of_service(self) -> CheckResult: ...

run_all runs the checks in this order and builds the report; with auto_warn a failing check emits one warning with the summary. A check that raises out of its own handling fails with the error text.

CheckRequestPasses when
get_confighelp.getConfigthe request succeeds; the detail names the DC
nearest_dchelp.getNearestDcthe request succeeds; the detail names the country and DCs
current_sessionaccount.getAuthorizationsthe current session is flagged official_app
layer_matchnonethe installed Telethon layer is within 15 of LAYER
lang_packlangpack.getLanguagesthe request for the client’s lang pack succeeds; an empty lang pack passes without a request
app_updatehelp.getAppUpdatethe request succeeds; the detail tells whether an update is offered
terms_of_servicehelp.getTermsOfServiceUpdatethe request succeeds

ConsistencyReport

opentele2/consistency.py
@dataclass class ConsistencyReport: checks: list[CheckResult] = field(default_factory=list) @property def all_passed(self) -> bool: ... @property def summary(self) -> str: ...
NameDescription
checksOne result per check, in run order.
all_passedWhether every check passed.
summaryA count line, then one [OK] name: detail or [FAIL] name: detail line per check; also str() of the report.

CheckResult

opentele2/consistency.py
@dataclass class CheckResult: name: str passed: bool detail: str = "" server_response: Any = None

server_response holds the Telethon object the server answered with, None for a check without a request or one that failed.

checks.py
import asyncio from opentele2.td import TDesktop from opentele2.api import UseCurrentSession async def main(): client = await TDesktop("tdata").ToTelethon("checks.session", UseCurrentSession) await client.connect() report = await client.RunConsistencyChecks(auto_warn=False) print(report.summary) print(report.all_passed) asyncio.run(main())
Last updated on