ptgc
A typed MTProto client for logging in as a real Telegram user account and controlling chats and channels — ban, kick, restrict, promote, invite, and list members — plus contacts, dialogs, and messaging.
Where ptgb (the companion package) talks to Telegram as a bot, ptgc talks to Telegram as a user, which is the only way to do the things a bot API token simply can’t.
import 'package:ptgc/ptgc.dart';
Future<void> main() async {
final client = TelegramClient.fromEnv(); // reads API_ID / API_HASH from .env
await client.connect();
if (!client.isSignedIn) {
final sent = await client.auth.sendCode('+15551234567');
final result = await client.auth.signIn(code: '12345', phoneCodeHash: sent.phoneCodeHash);
if (result.status == SignInStatus.passwordRequired) {
await client.auth.checkPassword('your 2FA password');
}
}
final me = await client.contacts.resolveUsername('someone');
if (me != null) await client.members.ban(chatId, me.id);
await client.disconnect();
}
Getting Started
Install the package, get your API credentials, and log in for the first time.
Examples
Forty-one runnable programs, from a first login to a full moderated group setup.
API Reference
Every public method, grouped by namespace — auth, chats, members, contacts, and more.
FAQ
Common questions about accounts, rate limits, sessions, and errors.
Why ptgc
- Real user-account control — ban, kick, restrict, promote, and invite members the way only a logged-in account (or an admin bot) can, via
Members. - A typed session, not raw MTProto —
TelegramClient.fromEnv()handles the handshake, data-center migration, and session persistence; you work withclient.auth,client.chats,client.members,client.contacts, andclient.messages. - Automatic peer resolution — every call feeds the users/chats it sees into a
PeerCache, so you can address a chat or user by plain integer ID afterwards without threading access hashes through your own code. - Typed permissions —
AdminRightsandBannedRightsreplace Telegram’s boolean-flag grab bags with named, documented fields. - A low-level escape hatch (
client.invoke,client.raw) for any MTProto method that doesn’t have a typed wrapper yet — the same error handling and DC-migration logic every namespace method gets. - A live event stream (
client.events) for new messages and membership/admin changes, without hand-rolling update parsing.
Install
dart pub add ptgc
- Package: ptgc on pub.dev
- Repository: psdkjoon/ptgc
- License: MIT
- Requires: Dart SDK
^3.5.0