telers/methods/send_sticker.rs
1use crate::client::Bot;
2use serde::Serialize;
3/// Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. On success, the sent Message is returned.
4/// # Documentation
5/// <https://core.telegram.org/bots/api#sendsticker>
6/// # Returns
7/// - `crate::types::Message`
8#[derive(Clone, Debug, Serialize)]
9pub struct SendSticker {
10 /// Unique identifier of the business connection on behalf of which the message will be sent
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub business_connection_id: Option<Box<str>>,
13 /// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
14 pub chat_id: crate::types::ChatIdKind,
15 /// Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub message_thread_id: Option<i64>,
18 /// Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub direct_messages_topic_id: Option<i64>,
21 /// 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.
22 pub sticker: crate::types::InputFile,
23 /// Emoji associated with the sticker; only for just uploaded stickers
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub emoji: Option<Box<str>>,
26 /// Sends the message silently. Users will receive a notification with no sound.
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub disable_notification: Option<bool>,
29 /// Protects the contents of the sent message from forwarding and saving
30 #[serde(skip_serializing_if = "Option::is_none")]
31 pub protect_content: Option<bool>,
32 /// Pass `true` to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub allow_paid_broadcast: Option<bool>,
35 /// Unique identifier of the message effect to be added to the message; for private chats only
36 #[serde(skip_serializing_if = "Option::is_none")]
37 pub message_effect_id: Option<Box<str>>,
38 /// A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
39 #[serde(skip_serializing_if = "Option::is_none")]
40 pub suggested_post_parameters: Option<crate::types::SuggestedPostParameters>,
41 /// Description of the message to reply to
42 #[serde(skip_serializing_if = "Option::is_none")]
43 pub reply_parameters: Option<crate::types::ReplyParameters>,
44 /// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub reply_markup: Option<crate::types::ReplyMarkup>,
47}
48impl SendSticker {
49 /// Creates a new `SendSticker`.
50 ///
51 /// # Arguments
52 /// * `chat_id` - Unique identifier for the target chat or username of the target channel (in the format @channelusername)
53 /// * `sticker` - 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.
54 ///
55 /// # Notes
56 /// Use builder methods to set optional fields.
57 #[must_use]
58 pub fn new<T0: Into<crate::types::ChatIdKind>, T1: Into<crate::types::InputFile>>(
59 chat_id: T0,
60 sticker: T1,
61 ) -> Self {
62 Self {
63 business_connection_id: None,
64 chat_id: chat_id.into(),
65 message_thread_id: None,
66 direct_messages_topic_id: None,
67 sticker: sticker.into(),
68 emoji: None,
69 disable_notification: None,
70 protect_content: None,
71 allow_paid_broadcast: None,
72 message_effect_id: None,
73 suggested_post_parameters: None,
74 reply_parameters: None,
75 reply_markup: None,
76 }
77 }
78
79 /// Unique identifier of the business connection on behalf of which the message will be sent
80 #[must_use]
81 pub fn business_connection_id<T: Into<Box<str>>>(self, val: T) -> Self {
82 let mut this = self;
83 this.business_connection_id = Some(val.into());
84 this
85 }
86
87 /// Unique identifier of the business connection on behalf of which the message will be sent
88 #[must_use]
89 pub fn business_connection_id_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
90 let mut this = self;
91 this.business_connection_id = val.map(Into::into);
92 this
93 }
94
95 /// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
96 #[must_use]
97 pub fn chat_id<T: Into<crate::types::ChatIdKind>>(self, val: T) -> Self {
98 let mut this = self;
99 this.chat_id = val.into();
100 this
101 }
102
103 /// Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only
104 #[must_use]
105 pub fn message_thread_id<T: Into<i64>>(self, val: T) -> Self {
106 let mut this = self;
107 this.message_thread_id = Some(val.into());
108 this
109 }
110
111 /// Unique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only
112 #[must_use]
113 pub fn message_thread_id_option<T: Into<i64>>(self, val: Option<T>) -> Self {
114 let mut this = self;
115 this.message_thread_id = val.map(Into::into);
116 this
117 }
118
119 /// Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
120 #[must_use]
121 pub fn direct_messages_topic_id<T: Into<i64>>(self, val: T) -> Self {
122 let mut this = self;
123 this.direct_messages_topic_id = Some(val.into());
124 this
125 }
126
127 /// Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
128 #[must_use]
129 pub fn direct_messages_topic_id_option<T: Into<i64>>(self, val: Option<T>) -> Self {
130 let mut this = self;
131 this.direct_messages_topic_id = val.map(Into::into);
132 this
133 }
134
135 /// 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.
136 #[must_use]
137 pub fn sticker<T: Into<crate::types::InputFile>>(self, val: T) -> Self {
138 let mut this = self;
139 this.sticker = val.into();
140 this
141 }
142
143 /// Emoji associated with the sticker; only for just uploaded stickers
144 #[must_use]
145 pub fn emoji<T: Into<Box<str>>>(self, val: T) -> Self {
146 let mut this = self;
147 this.emoji = Some(val.into());
148 this
149 }
150
151 /// Emoji associated with the sticker; only for just uploaded stickers
152 #[must_use]
153 pub fn emoji_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
154 let mut this = self;
155 this.emoji = val.map(Into::into);
156 this
157 }
158
159 /// Sends the message silently. Users will receive a notification with no sound.
160 #[must_use]
161 pub fn disable_notification<T: Into<bool>>(self, val: T) -> Self {
162 let mut this = self;
163 this.disable_notification = Some(val.into());
164 this
165 }
166
167 /// Sends the message silently. Users will receive a notification with no sound.
168 #[must_use]
169 pub fn disable_notification_option<T: Into<bool>>(self, val: Option<T>) -> Self {
170 let mut this = self;
171 this.disable_notification = val.map(Into::into);
172 this
173 }
174
175 /// Protects the contents of the sent message from forwarding and saving
176 #[must_use]
177 pub fn protect_content<T: Into<bool>>(self, val: T) -> Self {
178 let mut this = self;
179 this.protect_content = Some(val.into());
180 this
181 }
182
183 /// Protects the contents of the sent message from forwarding and saving
184 #[must_use]
185 pub fn protect_content_option<T: Into<bool>>(self, val: Option<T>) -> Self {
186 let mut this = self;
187 this.protect_content = val.map(Into::into);
188 this
189 }
190
191 /// Pass `true` to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
192 #[must_use]
193 pub fn allow_paid_broadcast<T: Into<bool>>(self, val: T) -> Self {
194 let mut this = self;
195 this.allow_paid_broadcast = Some(val.into());
196 this
197 }
198
199 /// Pass `true` to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
200 #[must_use]
201 pub fn allow_paid_broadcast_option<T: Into<bool>>(self, val: Option<T>) -> Self {
202 let mut this = self;
203 this.allow_paid_broadcast = val.map(Into::into);
204 this
205 }
206
207 /// Unique identifier of the message effect to be added to the message; for private chats only
208 #[must_use]
209 pub fn message_effect_id<T: Into<Box<str>>>(self, val: T) -> Self {
210 let mut this = self;
211 this.message_effect_id = Some(val.into());
212 this
213 }
214
215 /// Unique identifier of the message effect to be added to the message; for private chats only
216 #[must_use]
217 pub fn message_effect_id_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
218 let mut this = self;
219 this.message_effect_id = val.map(Into::into);
220 this
221 }
222
223 /// A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
224 #[must_use]
225 pub fn suggested_post_parameters<T: Into<crate::types::SuggestedPostParameters>>(
226 self,
227 val: T,
228 ) -> Self {
229 let mut this = self;
230 this.suggested_post_parameters = Some(val.into());
231 this
232 }
233
234 /// A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
235 #[must_use]
236 pub fn suggested_post_parameters_option<T: Into<crate::types::SuggestedPostParameters>>(
237 self,
238 val: Option<T>,
239 ) -> Self {
240 let mut this = self;
241 this.suggested_post_parameters = val.map(Into::into);
242 this
243 }
244
245 /// Description of the message to reply to
246 #[must_use]
247 pub fn reply_parameters<T: Into<crate::types::ReplyParameters>>(self, val: T) -> Self {
248 let mut this = self;
249 this.reply_parameters = Some(val.into());
250 this
251 }
252
253 /// Description of the message to reply to
254 #[must_use]
255 pub fn reply_parameters_option<T: Into<crate::types::ReplyParameters>>(
256 self,
257 val: Option<T>,
258 ) -> Self {
259 let mut this = self;
260 this.reply_parameters = val.map(Into::into);
261 this
262 }
263
264 /// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
265 #[must_use]
266 pub fn reply_markup<T: Into<crate::types::ReplyMarkup>>(self, val: T) -> Self {
267 let mut this = self;
268 this.reply_markup = Some(val.into());
269 this
270 }
271
272 /// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
273 #[must_use]
274 pub fn reply_markup_option<T: Into<crate::types::ReplyMarkup>>(self, val: Option<T>) -> Self {
275 let mut this = self;
276 this.reply_markup = val.map(Into::into);
277 this
278 }
279}
280impl super::TelegramMethod for SendSticker {
281 type Method = Self;
282 type Return = crate::types::Message;
283
284 fn build_request<Client>(mut self, _bot: &Bot<Client>) -> super::Request<Self::Method> {
285 let mut files = vec![];
286 super::prepare_file(&mut files, &mut self.sticker);
287 super::Request::new("sendSticker", self, Some(files))
288 }
289}