#![allow(unused)]
fn main() {
// Fetch up to N dialogs (returns the most recent first)
let dialogs = client.get_dialogs(50).await?;
for d in &dialogs {
println!("{}: {} unread: top msg: {}",
d.title(), d.unread_count(), d.top_message());
}
}
#![allow(unused)]
fn main() {
let mut iter = client.iter_dialogs();
// Total count (available after first page is fetched)
if let Some(total) = iter.total() {
println!("Total dialogs: {total}");
}
while let Some(dialog) = iter.next(&client).await? {
println!("{}", dialog.title());
}
}
#![allow(unused)]
fn main() {
let mut iter = client.iter_messages(peer.clone());
// Total count of messages in this chat
if let Some(total) = iter.total() {
println!("Total messages: {total}");
}
while let Some(msg) = iter.next(&client).await? {
println!("[{}] {}", msg.id, msg.message);
}
}
Method
Description
client.iter_messages(peer)
Create iterator (newest first)
iter.total()
Option<i32>: total message count after first fetch
#![allow(unused)]
fn main() {
// Latest N messages from a peer
let messages = client.get_message_history(peer.clone(), 20, 0, 0).await?;
// Specific message IDs
let messages = client.get_messages(peer.clone(), &[100, 101, 102]).await?;
// Returns Vec<Option<tl::enums::Message>>: None if not found
// Pinned message
let pinned = client.get_pinned_message(peer.clone()).await?;
// Fetch the message a reply refers to by ID
let parent = client.get_messages(peer.clone(), &[reply_id]).await?.into_iter().next();
}
#![allow(unused)]
fn main() {
// Mark all messages as read
client.mark_read(peer.clone()).await?;
// Clear @mention badges
client.clear_mentions(peer.clone()).await?;
// Leave and remove from dialog list
client.delete_dialog(peer.clone()).await?;
// Pin / unpin a dialog
client.pin_dialog(peer.clone(), true).await?;
client.pin_dialog(peer.clone(), false).await?;
// Get pinned dialogs (folder_id: 0 = main, 1 = archived)
let pinned = client.get_pinned_dialogs(0).await?;
// Set manual unread flag on a dialog
client.mark_dialog_unread(peer.clone()).await?;
// Clear the manual unread flag
client.mark_read(peer.clone()).await?;
// Join a public group/channel
client.join_chat("@somegroup").await?;
// Accept a private invite link
client.join_link("https://t.me/joinchat/AbCdEfG").await?;
// Parse invite hash from any link format
let hash = Client::parse_invite_hash("https://t.me/+AbCdEfG12345");
}
Move a dialog into the Telegram archive (folder 1) or back to the main list (folder 0):
#![allow(unused)]
fn main() {
// Move to archive - chat disappears from the main dialog list
client.archive("@somebot", true).await?;
// Move back to main list
client.archive("@somebot", false).await?;
}
Archived chats still receive messages; they are simply hidden from the main list and muted by default until the user opens them.