vaegram 0.2.0

Telegram MTProto client library for users and bots
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::Client;
use crate::dispatcher::Entities;
use crate::errors::Result;
use crate::raw::{base, functions};
use crate::types::User;

impl Client {
    /// Returns all your contacts.
    pub async fn get_contacts(&self) -> Result<Vec<User>> {
        let found = match self.invoke(&functions::contacts::GetContacts { hash: 0 }).await? {
            base::contacts::Contacts::Contacts(found) => found,
            // Only sent back for a non-zero hash.
            base::contacts::Contacts::ContactsNotModified => return Ok(Vec::new()),
        };
        let entities = Entities::new(self, found.users, Vec::new());
        Ok(found.contacts.iter().map(|base::Contact::Contact(c)| User::parse(c.user_id, &entities)).collect())
    }
}