Chats & Dialogs
Part of the API Reference. Reached via client.chats. Lists your dialogs and manages chats/channels themselves — creating, joining, leaving, renaming, and fetching full info. For acting on members of a chat (ban/kick/promote/list), see Member Management instead.
listDialogs
Future<List<PtgcChat>> listDialogs({
int limit = 100,
DateTime? offsetDate,
int offsetId = 0,
int offsetPeerId = 0,
}) async {
Lists your open conversations (DMs, groups, channels), most recently active first. limit caps how many come back in one call; page further by passing the last returned chat’s info as offsetDate/offsetId/offsetPeerId.
resolveUsername
Future<PtgcChat?> resolveUsername(String username) async {
Resolves @username (leading @ optional) to a PtgcChat — the group/supergroup/channel counterpart to Contacts.resolveUsername. Also caches the access hash ptgc needs to act on this chat by plain ID afterwards (e.g. with Members or elsewhere in this class).
Returns null if the username doesn’t exist, or belongs to a user rather than a chat — use Contacts.resolveUsername for those. Basic (non-super) groups never have a username, so this only ever resolves to a ChatKind.supergroup or ChatKind.channel.
getFullInfo
Future<PtgcChat> getFullInfo(int chatId) async {
Fetches extended info for chatId — description (“about”), member count, etc — beyond what [listDialogs]/Members.list already give you.
createGroup
Future<int?> createGroup(String title, List<int> userIds) async {
Creates a new basic group with title, starting with userIds as members (Telegram requires at least one). Basic groups cap out at 200 members — for anything bigger, or if you want channel features (public username, admin hierarchy beyond one level, etc), use [createSupergroup]/[createChannel] instead.
createSupergroup
Future<int?> createSupergroup(String title, {String about = ''}) =>
Creates a new supergroup (a megagroup channel) with title. Unlike [createGroup], supergroups scale past 200 members and support a proper admin hierarchy — most “groups” you see on Telegram are actually this.
createChannel
Future<int?> createChannel(String title, {String about = ''}) =>
Creates a new broadcast channel with title — only admins can post; everyone else just reads.
setTitle
Future<void> setTitle(int chatId, String title) async {
Renames chatId.
join
Future<void> join(int chatId) async {
Joins the public supergroup/channel chatId (you must already know its ID/access hash — resolve a @username with Contacts.resolveUsername first if needed). For private chats, use [joinByInviteLink] instead.
joinByInviteLink
Future<void> joinByInviteLink(String linkOrHash) async {
Joins a private chat via an invite link or its bare hash (the part after t.me/+ or t.me/joinchat/).
exportInviteLink
Future<String> exportInviteLink(int chatId) async {
Creates (or refreshes) an invite link for chatId. Requires the AdminRights.inviteUsers right if you’re not the creator.
leave
Future<void> leave(int chatId) async {
Leaves chatId. Does not delete the chat, and (for groups you don’t own) does not affect anyone else in it.
Types
PtgcChat
Returned throughout this namespace and Member Management.
| Field | Type | Meaning |
|---|---|---|
id |
int |
The chat’s numeric ID. |
accessHash |
int? |
Needed alongside id for most raw calls. Always present for supergroups/channels; null for plain groups, addressed by id alone. |
title |
String |
|
kind |
ChatKind |
See below. |
username |
String? |
Without the leading @. Only public supergroups/channels have one. |
participantsCount |
int? |
Best-effort member count; call [getFullInfo] if you need it guaranteed. |
isCreator / isVerified / isScam / isFake |
bool |
|
isLeft |
bool |
True if you’ve left this chat, or (for a basic group) it was deactivated/upgraded to a supergroup. |
isForbidden |
bool |
True if the chat is forbidden to you (e.g. you were banned) — most other fields will be unavailable in that case. |
adminRights |
AdminRights? |
This account’s admin rights in the chat, if any — see Permissions & Rights. |
ChatKind
| Value | Meaning |
|---|---|
private |
A one-on-one private chat with a user — surfaced here for completeness when working with dialogs. |
group |
A basic (non-super) group, capped at 200 members. |
supergroup |
A channel under the hood with megagroup set — what most large/public “groups” actually are. |
channel |
A broadcast channel. |