1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
use crate::client::Bot;
use serde::Serialize;
/// Posts a story on behalf of a managed business account. Requires the `can_manage_stories` business bot right. Returns Story on success.
/// # Documentation
/// <https://core.telegram.org/bots/api#poststory>
/// # Returns
/// - `crate::types::Story`
#[derive(Clone, Debug, Serialize)]
pub struct PostStory {
/// Unique identifier of the business connection
pub business_connection_id: Box<str>,
/// Content of the story
pub content: crate::types::InputStoryContent,
/// Period after which the story is moved to the archive, in seconds; must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400
pub active_period: i64,
/// Caption of the story, 0-2048 characters after entities parsing
#[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<Box<str>>,
/// Mode for parsing entities in the story caption. See formatting options for more details.
#[serde(skip_serializing_if = "Option::is_none")]
pub parse_mode: Option<Box<str>>,
/// A JSON-serialized list of special entities that appear in the caption, which can be specified instead of `parse_mode`
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_entities: Option<Box<[crate::types::MessageEntity]>>,
/// A JSON-serialized list of clickable areas to be shown on the story
#[serde(skip_serializing_if = "Option::is_none")]
pub areas: Option<Box<[crate::types::StoryArea]>>,
/// Pass `true` to keep the story accessible after it expires
#[serde(skip_serializing_if = "Option::is_none")]
pub post_to_chat_page: Option<bool>,
/// Pass `true` if the content of the story must be protected from forwarding and screenshotting
#[serde(skip_serializing_if = "Option::is_none")]
pub protect_content: Option<bool>,
}
impl PostStory {
/// Creates a new `PostStory`.
///
/// # Arguments
/// * `business_connection_id` - Unique identifier of the business connection
/// * `content` - Content of the story
/// * `active_period` - Period after which the story is moved to the archive, in seconds; must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new<T0: Into<Box<str>>, T1: Into<crate::types::InputStoryContent>, T2: Into<i64>>(
business_connection_id: T0,
content: T1,
active_period: T2,
) -> Self {
Self {
business_connection_id: business_connection_id.into(),
content: content.into(),
active_period: active_period.into(),
caption: None,
parse_mode: None,
caption_entities: None,
areas: None,
post_to_chat_page: None,
protect_content: None,
}
}
/// Unique identifier of the business connection
#[must_use]
pub fn business_connection_id<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.business_connection_id = val.into();
this
}
/// Content of the story
#[must_use]
pub fn content<T: Into<crate::types::InputStoryContent>>(self, val: T) -> Self {
let mut this = self;
this.content = val.into();
this
}
/// Period after which the story is moved to the archive, in seconds; must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400
#[must_use]
pub fn active_period<T: Into<i64>>(self, val: T) -> Self {
let mut this = self;
this.active_period = val.into();
this
}
/// Caption of the story, 0-2048 characters after entities parsing
#[must_use]
pub fn caption<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.caption = Some(val.into());
this
}
/// Caption of the story, 0-2048 characters after entities parsing
#[must_use]
pub fn caption_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
let mut this = self;
this.caption = val.map(Into::into);
this
}
/// Mode for parsing entities in the story caption. See formatting options for more details.
#[must_use]
pub fn parse_mode<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.parse_mode = Some(val.into());
this
}
/// Mode for parsing entities in the story caption. See formatting options for more details.
#[must_use]
pub fn parse_mode_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
let mut this = self;
this.parse_mode = val.map(Into::into);
this
}
/// A JSON-serialized list of special entities that appear in the caption, which can be specified instead of `parse_mode`
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn caption_entities<
TItem: Into<crate::types::MessageEntity>,
T: IntoIterator<Item = TItem>,
>(
self,
val: T,
) -> Self {
let mut this = self;
this.caption_entities = Some(
this.caption_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(val.into_iter().map(Into::into))
.collect(),
);
this
}
/// A JSON-serialized list of special entities that appear in the caption, which can be specified instead of `parse_mode`
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn caption_entity<T: Into<crate::types::MessageEntity>>(self, val: T) -> Self {
let mut this = self;
this.caption_entities = Some(
this.caption_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect(),
);
this
}
/// A JSON-serialized list of special entities that appear in the caption, which can be specified instead of `parse_mode`
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn caption_entities_option<
TItem: Into<crate::types::MessageEntity>,
T: IntoIterator<Item = TItem>,
>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.caption_entities = val.map(|v| v.into_iter().map(Into::into).collect());
this
}
/// A JSON-serialized list of clickable areas to be shown on the story
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn areas<TItem: Into<crate::types::StoryArea>, T: IntoIterator<Item = TItem>>(
self,
val: T,
) -> Self {
let mut this = self;
this.areas = Some(
this.areas
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(val.into_iter().map(Into::into))
.collect(),
);
this
}
/// A JSON-serialized list of clickable areas to be shown on the story
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn area<T: Into<crate::types::StoryArea>>(self, val: T) -> Self {
let mut this = self;
this.areas = Some(
this.areas
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect(),
);
this
}
/// A JSON-serialized list of clickable areas to be shown on the story
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn areas_option<TItem: Into<crate::types::StoryArea>, T: IntoIterator<Item = TItem>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.areas = val.map(|v| v.into_iter().map(Into::into).collect());
this
}
/// Pass `true` to keep the story accessible after it expires
#[must_use]
pub fn post_to_chat_page<T: Into<bool>>(self, val: T) -> Self {
let mut this = self;
this.post_to_chat_page = Some(val.into());
this
}
/// Pass `true` to keep the story accessible after it expires
#[must_use]
pub fn post_to_chat_page_option<T: Into<bool>>(self, val: Option<T>) -> Self {
let mut this = self;
this.post_to_chat_page = val.map(Into::into);
this
}
/// Pass `true` if the content of the story must be protected from forwarding and screenshotting
#[must_use]
pub fn protect_content<T: Into<bool>>(self, val: T) -> Self {
let mut this = self;
this.protect_content = Some(val.into());
this
}
/// Pass `true` if the content of the story must be protected from forwarding and screenshotting
#[must_use]
pub fn protect_content_option<T: Into<bool>>(self, val: Option<T>) -> Self {
let mut this = self;
this.protect_content = val.map(Into::into);
this
}
}
impl super::TelegramMethod for PostStory {
type Method = Self;
type Return = crate::types::Story;
fn build_request<Client>(mut self, _bot: &Bot<Client>) -> super::Request<Self::Method> {
let mut files = vec![];
super::prepare_input_story_content(&mut files, &mut self.content);
super::Request::new("postStory", self, Some(files))
}
}