ptgc
MTProto client for Dart

Authentication

Part of the API Reference. Reached via client.auth — see Authentication Flow for a walkthrough of the whole login process.

sendCode

Future<SentCode> sendCode(String phoneNumber) async {

Requests a login code for phoneNumber (international format, e.g. '+15551234567'). Telegram will deliver it via the app if the number is already registered on another device, otherwise by SMS/call.

signIn

Future<SignInResult> signIn({
  required String code,
  String? phoneNumber,
  String? phoneCodeHash,
}) async {

Submits the code the user received after [sendCode]. Uses the phone number and code hash from the last [sendCode] call unless you pass them explicitly (useful if you’re not holding onto the SentCode).

checkPassword

Future<PtgcUser> checkPassword(String password) async {

Submits the account’s Two-Factor Authentication password after [signIn] returned SignInStatus.passwordRequired.

logOut

Future<void> logOut() async {

Logs out and invalidates this session. After this, TelegramClient needs a full [sendCode]/[signIn] to be usable again — consider TelegramClient.disconnect instead if you just want to stop using the connection for now without revoking it.

Types

SentCode

Returned by [sendCode]. Pass phoneCodeHash back to [signIn] along with the code.

Field Type Meaning
phoneCodeHash String Pass this back to signIn.
viaApp bool True if the code was (or will be) sent as a Telegram app notification rather than SMS/call.
timeout Duration? How long before the code expires / a different delivery method becomes available, if Telegram specified one.

SignInResult

Returned by [signIn].

Field Type Meaning
status SignInStatus What happened — see below.
user PtgcUser? Set when status is SignInStatus.success.
passwordHint String? Set when status is SignInStatus.passwordRequired — the account owner’s own hint for their 2FA password, if they set one.

SignInStatus

Value Meaning
success Logged in — no further steps needed.
passwordRequired Correct code, but this account has Two-Factor Authentication enabled. Call [checkPassword] next.
signUpRequired This phone number has no Telegram account yet. ptgc doesn’t wrap account creation (auth.signUp) on purpose — it’s one raw client.invoke call away if you have a genuine need.