vaegram 0.3.0

Telegram MTProto client library for users and bots
Documentation
use crate::Client;
use crate::errors::Result;
use crate::raw::functions;
use crate::types::User;

impl Client {
    /// Creates an account for a new number, then signs in and saves the session.
    ///
    /// Pass the `phone_code_hash` of the login code, after [`sign_in`](Client::sign_in) failed with
    /// `Error::SignUpRequired`.
    pub async fn sign_up(
        &self,
        phone_number: &str,
        phone_code_hash: &str,
        first_name: &str,
        last_name: &str,
    ) -> Result<User> {
        let request = functions::auth::SignUp {
            no_joined_notifications: false,
            phone_number: phone_number.into(),
            phone_code_hash: phone_code_hash.into(),
            first_name: first_name.into(),
            last_name: last_name.into(),
        };
        let auth = self.invoke(&request).await?;
        self.authorized(auth).await
    }
}

#[cfg(test)]
mod tests {
    use crate::Client;
    use crate::raw::{Serializable, functions};

    #[tokio::test]
    async fn sends_the_names_with_the_code_hash() {
        let (client, mut sent) = Client::recording();
        let _ = client.sign_up("8801", "hash", "Ada", "").await;
        let expected = functions::auth::SignUp {
            no_joined_notifications: false,
            phone_number: "8801".into(),
            phone_code_hash: "hash".into(),
            first_name: "Ada".into(),
            last_name: String::new(),
        };
        assert_eq!(sent.recv().await.unwrap(), expected.to_bytes());
    }
}