Skip to main content

rust_tg_bot_raw/bot/
stickers.rs

1use super::{input_file_param, push_opt, push_opt_file, push_opt_str, Bot, ChatId, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::{files, message, reply, suggested_post};
4
5#[allow(dead_code)]
6impl Bot {
7    // ======================================================================
8    // Stickers
9    // ======================================================================
10
11    /// Sends a sticker. Internal raw method used by builder APIs.
12    ///
13    /// Calls the Telegram `sendSticker` API method.
14    pub async fn send_sticker_raw(
15        &self,
16        chat_id: ChatId,
17        sticker: files::input_file::InputFile,
18        emoji: Option<&str>,
19        disable_notification: Option<bool>,
20        protect_content: Option<bool>,
21        reply_parameters: Option<reply::ReplyParameters>,
22        reply_markup: Option<serde_json::Value>,
23        message_thread_id: Option<i64>,
24        business_connection_id: Option<&str>,
25        message_effect_id: Option<&str>,
26        allow_paid_broadcast: Option<bool>,
27        direct_messages_topic_id: Option<i64>,
28        suggested_post_parameters: Option<suggested_post::SuggestedPostParameters>,
29    ) -> Result<message::Message> {
30        let mut params = vec![
31            RequestParameter::new("chat_id", serde_json::to_value(&chat_id)?),
32            input_file_param("sticker", sticker),
33        ];
34        push_opt_str(&mut params, "emoji", emoji);
35        push_opt(&mut params, "disable_notification", &disable_notification)?;
36        push_opt(&mut params, "protect_content", &protect_content)?;
37        push_opt(&mut params, "reply_parameters", &reply_parameters)?;
38        push_opt(&mut params, "reply_markup", &reply_markup)?;
39        push_opt(&mut params, "message_thread_id", &message_thread_id)?;
40        push_opt_str(
41            &mut params,
42            "business_connection_id",
43            business_connection_id,
44        );
45        push_opt_str(&mut params, "message_effect_id", message_effect_id);
46        push_opt(&mut params, "allow_paid_broadcast", &allow_paid_broadcast)?;
47        push_opt(
48            &mut params,
49            "direct_messages_topic_id",
50            &direct_messages_topic_id,
51        )?;
52        push_opt(
53            &mut params,
54            "suggested_post_parameters",
55            &suggested_post_parameters,
56        )?;
57        self.do_post("sendSticker", params).await
58    }
59
60    /// Use this method to get a sticker set by name.
61    ///
62    /// Calls the Telegram `getStickerSet` API method.
63    pub async fn get_sticker_set_raw(&self, name: &str) -> Result<files::sticker::StickerSet> {
64        let params = vec![RequestParameter::new(
65            "name",
66            serde_json::Value::String(name.to_owned()),
67        )];
68        self.do_post("getStickerSet", params).await
69    }
70
71    /// Use this method to get information about custom emoji stickers by their identifiers.
72    ///
73    /// Calls the Telegram `getCustomEmojiStickers` API method.
74    pub async fn get_custom_emoji_stickers_raw(
75        &self,
76        custom_emoji_ids: Vec<String>,
77    ) -> Result<Vec<files::sticker::Sticker>> {
78        let params = vec![RequestParameter::new(
79            "custom_emoji_ids",
80            serde_json::to_value(&custom_emoji_ids)?,
81        )];
82        self.do_post("getCustomEmojiStickers", params).await
83    }
84
85    /// Use this method to upload a sticker file for later use in sticker sets.
86    ///
87    /// Calls the Telegram `uploadStickerFile` API method.
88    pub async fn upload_sticker_file_raw(
89        &self,
90        user_id: i64,
91        sticker: files::input_file::InputFile,
92        sticker_format: &str,
93    ) -> Result<files::file::File> {
94        let params = vec![
95            RequestParameter::new("user_id", serde_json::to_value(user_id)?),
96            input_file_param("sticker", sticker),
97            RequestParameter::new(
98                "sticker_format",
99                serde_json::Value::String(sticker_format.to_owned()),
100            ),
101        ];
102        self.do_post("uploadStickerFile", params).await
103    }
104
105    /// Use this method to create a new sticker set owned by a user.
106    ///
107    /// Calls the Telegram `createNewStickerSet` API method.
108    pub async fn create_new_sticker_set_raw(
109        &self,
110        user_id: i64,
111        name: &str,
112        title: &str,
113        stickers: Vec<serde_json::Value>,
114        sticker_type: Option<&str>,
115        needs_repainting: Option<bool>,
116    ) -> Result<bool> {
117        let mut params = vec![
118            RequestParameter::new("user_id", serde_json::to_value(user_id)?),
119            RequestParameter::new("name", serde_json::Value::String(name.to_owned())),
120            RequestParameter::new("title", serde_json::Value::String(title.to_owned())),
121            RequestParameter::new("stickers", serde_json::to_value(&stickers)?),
122        ];
123        push_opt_str(&mut params, "sticker_type", sticker_type);
124        push_opt(&mut params, "needs_repainting", &needs_repainting)?;
125        self.do_post("createNewStickerSet", params).await
126    }
127
128    /// Use this method to add a new sticker to an existing sticker set.
129    ///
130    /// Calls the Telegram `addStickerToSet` API method.
131    pub async fn add_sticker_to_set_raw(
132        &self,
133        user_id: i64,
134        name: &str,
135        sticker: serde_json::Value,
136    ) -> Result<bool> {
137        let params = vec![
138            RequestParameter::new("user_id", serde_json::to_value(user_id)?),
139            RequestParameter::new("name", serde_json::Value::String(name.to_owned())),
140            RequestParameter::new("sticker", sticker),
141        ];
142        self.do_post("addStickerToSet", params).await
143    }
144
145    /// Use this method to move a sticker in a set to a specific position.
146    ///
147    /// Calls the Telegram `setStickerPositionInSet` API method.
148    pub async fn set_sticker_position_in_set_raw(
149        &self,
150        sticker: &str,
151        position: i64,
152    ) -> Result<bool> {
153        let params = vec![
154            RequestParameter::new("sticker", serde_json::Value::String(sticker.to_owned())),
155            RequestParameter::new("position", serde_json::to_value(position)?),
156        ];
157        self.do_post("setStickerPositionInSet", params).await
158    }
159
160    /// Use this method to delete a sticker from a set.
161    ///
162    /// Calls the Telegram `deleteStickerFromSet` API method.
163    pub async fn delete_sticker_from_set_raw(&self, sticker: &str) -> Result<bool> {
164        let params = vec![RequestParameter::new(
165            "sticker",
166            serde_json::Value::String(sticker.to_owned()),
167        )];
168        self.do_post("deleteStickerFromSet", params).await
169    }
170
171    /// Use this method to replace an existing sticker in a sticker set with a new one.
172    ///
173    /// Calls the Telegram `replaceStickerInSet` API method.
174    pub async fn replace_sticker_in_set_raw(
175        &self,
176        user_id: i64,
177        name: &str,
178        old_sticker: &str,
179        sticker: serde_json::Value,
180    ) -> Result<bool> {
181        let params = vec![
182            RequestParameter::new("user_id", serde_json::to_value(user_id)?),
183            RequestParameter::new("name", serde_json::Value::String(name.to_owned())),
184            RequestParameter::new(
185                "old_sticker",
186                serde_json::Value::String(old_sticker.to_owned()),
187            ),
188            RequestParameter::new("sticker", sticker),
189        ];
190        self.do_post("replaceStickerInSet", params).await
191    }
192
193    /// Use this method to change the list of emoji assigned to a regular or custom emoji sticker.
194    ///
195    /// Calls the Telegram `setStickerEmojiList` API method.
196    pub async fn set_sticker_emoji_list_raw(
197        &self,
198        sticker: &str,
199        emoji_list: Vec<String>,
200    ) -> Result<bool> {
201        let params = vec![
202            RequestParameter::new("sticker", serde_json::Value::String(sticker.to_owned())),
203            RequestParameter::new("emoji_list", serde_json::to_value(&emoji_list)?),
204        ];
205        self.do_post("setStickerEmojiList", params).await
206    }
207
208    /// Use this method to change search keywords assigned to a regular or custom emoji sticker.
209    ///
210    /// Calls the Telegram `setStickerKeywords` API method.
211    pub async fn set_sticker_keywords_raw(
212        &self,
213        sticker: &str,
214        keywords: Option<Vec<String>>,
215    ) -> Result<bool> {
216        let mut params = vec![RequestParameter::new(
217            "sticker",
218            serde_json::Value::String(sticker.to_owned()),
219        )];
220        push_opt(&mut params, "keywords", &keywords)?;
221        self.do_post("setStickerKeywords", params).await
222    }
223
224    /// Use this method to change the mask position of a mask sticker.
225    ///
226    /// Calls the Telegram `setStickerMaskPosition` API method.
227    pub async fn set_sticker_mask_position_raw(
228        &self,
229        sticker: &str,
230        mask_position: Option<files::sticker::MaskPosition>,
231    ) -> Result<bool> {
232        let mut params = vec![RequestParameter::new(
233            "sticker",
234            serde_json::Value::String(sticker.to_owned()),
235        )];
236        push_opt(&mut params, "mask_position", &mask_position)?;
237        self.do_post("setStickerMaskPosition", params).await
238    }
239
240    /// Use this method to set the thumbnail of a regular or mask sticker set.
241    ///
242    /// Calls the Telegram `setStickerSetThumbnail` API method.
243    pub async fn set_sticker_set_thumbnail_raw(
244        &self,
245        name: &str,
246        user_id: i64,
247        format: &str,
248        thumbnail: Option<files::input_file::InputFile>,
249    ) -> Result<bool> {
250        let mut params = vec![
251            RequestParameter::new("name", serde_json::Value::String(name.to_owned())),
252            RequestParameter::new("user_id", serde_json::to_value(user_id)?),
253            RequestParameter::new("format", serde_json::Value::String(format.to_owned())),
254        ];
255        push_opt_file(&mut params, "thumbnail", thumbnail);
256        self.do_post("setStickerSetThumbnail", params).await
257    }
258
259    /// Use this method to set the title of a created sticker set.
260    ///
261    /// Calls the Telegram `setStickerSetTitle` API method.
262    pub async fn set_sticker_set_title_raw(&self, name: &str, title: &str) -> Result<bool> {
263        let params = vec![
264            RequestParameter::new("name", serde_json::Value::String(name.to_owned())),
265            RequestParameter::new("title", serde_json::Value::String(title.to_owned())),
266        ];
267        self.do_post("setStickerSetTitle", params).await
268    }
269
270    /// Use this method to set the thumbnail of a custom emoji sticker set.
271    ///
272    /// Calls the Telegram `setCustomEmojiStickerSetThumbnail` API method.
273    pub async fn set_custom_emoji_sticker_set_thumbnail_raw(
274        &self,
275        name: &str,
276        custom_emoji_id: Option<&str>,
277    ) -> Result<bool> {
278        let mut params = vec![RequestParameter::new(
279            "name",
280            serde_json::Value::String(name.to_owned()),
281        )];
282        push_opt_str(&mut params, "custom_emoji_id", custom_emoji_id);
283        self.do_post("setCustomEmojiStickerSetThumbnail", params)
284            .await
285    }
286
287    /// Use this method to delete a sticker set that was created by the bot.
288    ///
289    /// Calls the Telegram `deleteStickerSet` API method.
290    pub async fn delete_sticker_set_raw(&self, name: &str) -> Result<bool> {
291        let params = vec![RequestParameter::new(
292            "name",
293            serde_json::Value::String(name.to_owned()),
294        )];
295        self.do_post("deleteStickerSet", params).await
296    }
297
298    /// Use this method to get custom emoji stickers which can be used as a forum topic icon.
299    ///
300    /// Calls the Telegram `getForumTopicIconStickers` API method.
301    pub async fn get_forum_topic_icon_stickers_raw(&self) -> Result<Vec<files::sticker::Sticker>> {
302        self.do_post("getForumTopicIconStickers", Vec::new()).await
303    }
304}