conogram/methods/
send_sticker.rs

1use std::{
2    future::{Future, IntoFuture},
3    pin::Pin,
4};
5
6use serde::Serialize;
7
8use crate::{
9    api::API,
10    entities::{
11        message::Message,
12        misc::{
13            chat_id::ChatId,
14            input_file::{GetFiles, InputFile},
15            reply_markup::ReplyMarkup,
16        },
17        reply_parameters::ReplyParameters,
18    },
19    errors::ConogramError,
20    impl_into_future_multipart,
21    request::RequestT,
22    utils::deserialize_utils::is_false,
23};
24
25#[derive(Debug, Clone, Serialize)]
26pub struct SendStickerParams {
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub business_connection_id: Option<String>,
29    pub chat_id: ChatId,
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub message_thread_id: Option<i64>,
32    pub sticker: InputFile,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub emoji: Option<String>,
35    #[serde(default, skip_serializing_if = "is_false")]
36    pub disable_notification: bool,
37    #[serde(default, skip_serializing_if = "is_false")]
38    pub protect_content: bool,
39    #[serde(default, skip_serializing_if = "is_false")]
40    pub allow_paid_broadcast: bool,
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub message_effect_id: Option<String>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub reply_parameters: Option<ReplyParameters>,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub reply_markup: Option<ReplyMarkup>,
47}
48
49impl GetFiles for SendStickerParams {
50    fn get_files(&self) -> Vec<&InputFile> {
51        vec![&self.sticker]
52    }
53}
54impl_into_future_multipart!(SendStickerRequest<'a>);
55
56///Use this method to send static .WEBP, [animated](https://telegram.org/blog/animated-stickers) .TGS, or [video](https://telegram.org/blog/video-stickers-better-reactions) .WEBM stickers. On success, the sent [Message](https://core.telegram.org/bots/api/#message) is returned.
57#[derive(Clone)]
58pub struct SendStickerRequest<'a> {
59    api: &'a API,
60    params: SendStickerParams,
61}
62
63impl<'a> RequestT for SendStickerRequest<'a> {
64    type ParamsType = SendStickerParams;
65    type ReturnType = Message;
66    fn get_name() -> &'static str {
67        "sendSticker"
68    }
69    fn get_api_ref(&self) -> &API {
70        self.api
71    }
72    fn get_params_ref(&self) -> &Self::ParamsType {
73        &self.params
74    }
75    fn is_multipart() -> bool {
76        true
77    }
78}
79impl<'a> SendStickerRequest<'a> {
80    pub fn new(api: &'a API, chat_id: impl Into<ChatId>, sticker: impl Into<InputFile>) -> Self {
81        Self {
82            api,
83            params: SendStickerParams {
84                chat_id: chat_id.into(),
85                sticker: sticker.into(),
86                business_connection_id: Option::default(),
87                message_thread_id: Option::default(),
88                emoji: Option::default(),
89                disable_notification: bool::default(),
90                protect_content: bool::default(),
91                allow_paid_broadcast: bool::default(),
92                message_effect_id: Option::default(),
93                reply_parameters: Option::default(),
94                reply_markup: Option::default(),
95            },
96        }
97    }
98
99    ///Unique identifier of the business connection on behalf of which the message will be sent
100    #[must_use]
101    pub fn business_connection_id(mut self, business_connection_id: impl Into<String>) -> Self {
102        self.params.business_connection_id = Some(business_connection_id.into());
103        self
104    }
105
106    ///Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
107    #[must_use]
108    pub fn chat_id(mut self, chat_id: impl Into<ChatId>) -> Self {
109        self.params.chat_id = chat_id.into();
110        self
111    }
112
113    ///Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
114    #[must_use]
115    pub fn message_thread_id(mut self, message_thread_id: impl Into<i64>) -> Self {
116        self.params.message_thread_id = Some(message_thread_id.into());
117        self
118    }
119
120    ///Sticker to send. Pass a file\_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP sticker from the Internet, or upload a new .WEBP, .TGS, or .WEBM sticker using multipart/form-data. [More information on Sending Files ยป](https://core.telegram.org/bots/api/#sending-files). Video and animated stickers can't be sent via an HTTP URL.
121    #[must_use]
122    pub fn sticker(mut self, sticker: impl Into<InputFile>) -> Self {
123        self.params.sticker = sticker.into();
124        self
125    }
126
127    ///Emoji associated with the sticker; only for just uploaded stickers
128    #[must_use]
129    pub fn emoji(mut self, emoji: impl Into<String>) -> Self {
130        self.params.emoji = Some(emoji.into());
131        self
132    }
133
134    ///Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound.
135    #[must_use]
136    pub fn disable_notification(mut self, disable_notification: impl Into<bool>) -> Self {
137        self.params.disable_notification = disable_notification.into();
138        self
139    }
140
141    ///Protects the contents of the sent message from forwarding and saving
142    #[must_use]
143    pub fn protect_content(mut self, protect_content: impl Into<bool>) -> Self {
144        self.params.protect_content = protect_content.into();
145        self
146    }
147
148    ///Pass *True* to allow up to 1000 messages per second, ignoring [broadcasting limits](https://core.telegram.org/bots/faq#how-can-i-message-all-of-my-bot-39s-subscribers-at-once) for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
149    #[must_use]
150    pub fn allow_paid_broadcast(mut self, allow_paid_broadcast: impl Into<bool>) -> Self {
151        self.params.allow_paid_broadcast = allow_paid_broadcast.into();
152        self
153    }
154
155    ///Unique identifier of the message effect to be added to the message; for private chats only
156    #[must_use]
157    pub fn message_effect_id(mut self, message_effect_id: impl Into<String>) -> Self {
158        self.params.message_effect_id = Some(message_effect_id.into());
159        self
160    }
161
162    ///Description of the message to reply to
163    #[must_use]
164    pub fn reply_parameters(mut self, reply_parameters: impl Into<ReplyParameters>) -> Self {
165        self.params.reply_parameters = Some(reply_parameters.into());
166        self
167    }
168
169    ///Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user
170    #[must_use]
171    pub fn reply_markup(mut self, reply_markup: impl Into<ReplyMarkup>) -> Self {
172        self.params.reply_markup = Some(reply_markup.into());
173        self
174    }
175}
176
177impl API {
178    ///Use this method to send static .WEBP, [animated](https://telegram.org/blog/animated-stickers) .TGS, or [video](https://telegram.org/blog/video-stickers-better-reactions) .WEBM stickers. On success, the sent [Message](https://core.telegram.org/bots/api/#message) is returned.
179    pub fn send_sticker(
180        &self,
181        chat_id: impl Into<ChatId>,
182        sticker: impl Into<InputFile>,
183    ) -> SendStickerRequest {
184        SendStickerRequest::new(self, chat_id, sticker)
185    }
186}
187
188// Divider: all content below this line will be preserved after code regen