ptgc
MTProto client for Dart

Contacts

Part of the API Reference. Reached via client.contacts. Manages this account’s contacts and account-level (not per-chat) user blocking, and resolves usernames to the peers ptgc needs to act on them elsewhere.

resolveUsername

Future<PtgcUser?> resolveUsername(String username) async {

Resolves @username (leading @ optional) to a PtgcUser and caches its access hash, so you can pass the returned .id to Members and elsewhere afterwards.

Returns null if the username doesn’t exist. Works for user, group, and channel usernames alike, but only user results are returned here — use Chats.resolveUsername to resolve a chat username instead.

searchUsers

Future<List<PtgcUser>> searchUsers(String query, {int limit = 20}) async {

Searches for users/chats by name, both among your contacts and globally. limit caps how many of each category come back.

addContact

Future<void> addContact(
  int userId, {
  required String firstName,
  String lastName = '',
  String phone = '',
}) async {

Adds userId to your contacts. firstName/lastName are your own label for them, not pulled from their profile.

deleteContacts

Future<void> deleteContacts(List<int> userIds) async {

Removes userIds from your contacts (doesn’t block them — see [block] for that).

block

Future<void> block(int userId) async {

Blocks userId account-wide: they can no longer message you or see your online status, regardless of which chat you’re both in. This is separate from Members.ban, which only affects one specific chat.

unblock

Future<void> unblock(int userId) async {

Reverses [block].

getBlockedUsers

Future<List<PtgcUser>> getBlockedUsers(
    {int offset = 0, int limit = 100}) async {

Lists everyone you’ve [block]ed.

Types

PtgcUser

Returned throughout ptgc (contacts, participants, message senders, whoAmI, …).

Field Type Meaning
id int
accessHash int? Needed alongside id to address this user in most raw API calls. null for isDeleted users, which can no longer be addressed at all.
firstName / lastName String?
username String? Without the leading @.
phone String? E.164-ish, digits only, no leading +.
isBot / isSelf / isVerified / isPremium / isScam / isFake bool isSelf is true for the account ptgc itself is logged in as.
isDeleted bool True for a deleted account — most fields will be null and accessHash will always be null.

displayName (getter): first and last name joined with a space, falling back to '@username', then '#\$id', if no name is set.