Skip to main content

rust_tg_bot_raw/bot/
user_profile.rs

1use super::{push_opt, push_opt_str, Bot, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::{files, user_profile_audios, user_profile_photos};
4
5#[allow(dead_code)]
6impl Bot {
7    // ======================================================================
8    // User and profile
9    // ======================================================================
10
11    /// Use this method to get a list of profile pictures for a user.
12    ///
13    /// Calls the Telegram `getUserProfilePhotos` API method.
14    pub async fn get_user_profile_photos_raw(
15        &self,
16        user_id: i64,
17        offset: Option<i64>,
18        limit: Option<i64>,
19    ) -> Result<user_profile_photos::UserProfilePhotos> {
20        let mut params = vec![RequestParameter::new(
21            "user_id",
22            serde_json::to_value(user_id)?,
23        )];
24        push_opt(&mut params, "offset", &offset)?;
25        push_opt(&mut params, "limit", &limit)?;
26        self.do_post("getUserProfilePhotos", params).await
27    }
28
29    /// Use this method to get a list of profile audios for a user.
30    ///
31    /// Calls the Telegram `getUserProfileAudios` API method.
32    pub async fn get_user_profile_audios_raw(
33        &self,
34        user_id: i64,
35        offset: Option<i64>,
36        limit: Option<i64>,
37    ) -> Result<user_profile_audios::UserProfileAudios> {
38        let mut params = vec![RequestParameter::new(
39            "user_id",
40            serde_json::to_value(user_id)?,
41        )];
42        push_opt(&mut params, "offset", &offset)?;
43        push_opt(&mut params, "limit", &limit)?;
44        self.do_post("getUserProfileAudios", params).await
45    }
46
47    /// Use this method to change the emoji status for a given user.
48    ///
49    /// Calls the Telegram `setUserEmojiStatus` API method.
50    pub async fn set_user_emoji_status_raw(
51        &self,
52        user_id: i64,
53        emoji_status_custom_emoji_id: Option<&str>,
54        emoji_status_expiration_date: Option<i64>,
55    ) -> Result<bool> {
56        let mut params = vec![RequestParameter::new(
57            "user_id",
58            serde_json::to_value(user_id)?,
59        )];
60        push_opt_str(
61            &mut params,
62            "emoji_status_custom_emoji_id",
63            emoji_status_custom_emoji_id,
64        );
65        push_opt(
66            &mut params,
67            "emoji_status_expiration_date",
68            &emoji_status_expiration_date,
69        )?;
70        self.do_post("setUserEmojiStatus", params).await
71    }
72
73    /// Use this method to set the bot's profile photo.
74    ///
75    /// Calls the Telegram `setMyProfilePhoto` API method.
76    pub async fn set_my_profile_photo_raw(&self, photo: serde_json::Value) -> Result<bool> {
77        let params = vec![RequestParameter::new("photo", photo)];
78        self.do_post("setMyProfilePhoto", params).await
79    }
80
81    /// Use this method to remove the bot's profile photo.
82    ///
83    /// Calls the Telegram `removeMyProfilePhoto` API method.
84    pub async fn remove_my_profile_photo_raw(&self) -> Result<bool> {
85        self.do_post("removeMyProfilePhoto", Vec::new()).await
86    }
87
88    // ======================================================================
89    // Files
90    // ======================================================================
91
92    /// Gets basic info about a file and prepares it for downloading.
93    /// Internal raw method used by builder APIs.
94    ///
95    /// Calls the Telegram `getFile` API method.
96    pub async fn get_file_raw(&self, file_id: &str) -> Result<files::file::File> {
97        let params = vec![RequestParameter::new(
98            "file_id",
99            serde_json::Value::String(file_id.to_owned()),
100        )];
101        self.do_post("getFile", params).await
102    }
103}