conogram/methods/
send_sticker.rs1use 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#[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 #[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 #[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 #[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 #[must_use]
122 pub fn sticker(mut self, sticker: impl Into<InputFile>) -> Self {
123 self.params.sticker = sticker.into();
124 self
125 }
126
127 #[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 #[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 #[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 #[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 #[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 #[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 #[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 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