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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
use serde::{Deserialize, Serialize};
use crate::{
api::{Method, Payload, PayloadError},
types::{Chat, Float, Integer, LocationAddress, ReactionType},
};
/// Represents a story.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Story {
/// Chat that posted the story.
pub chat: Chat,
/// Unique identifier of the story in the chat.
pub id: Integer,
}
/// Describes a list of clickable areas on a story media.
#[derive(Clone, Debug, Serialize)]
#[serde(into = "Vec<StoryArea>")]
pub struct StoryAreas {
items: Vec<StoryArea>,
}
impl<T> From<T> for StoryAreas
where
T: IntoIterator<Item = StoryArea>,
{
fn from(value: T) -> Self {
Self {
items: value.into_iter().collect(),
}
}
}
impl From<StoryAreas> for Vec<StoryArea> {
fn from(value: StoryAreas) -> Self {
value.items
}
}
/// Describes a clickable area on a story media.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct StoryArea {
/// Type of the area.
#[serde(rename = "type")]
pub area_type: StoryAreaType,
/// Position of the area
pub position: StoryAreaPosition,
}
impl StoryArea {
/// Creates a new `StoryArea`.
///
/// # Arguments
///
/// * `area_type` - Type of the area.
/// * `position` - Position of the area.
pub fn new<T>(area_type: T, position: StoryAreaPosition) -> Self
where
T: Into<StoryAreaType>,
{
Self {
area_type: area_type.into(),
position,
}
}
}
/// Describes the position of a clickable area within a story.
#[derive(Clone, Debug, Deserialize, derive_more::From, PartialEq, PartialOrd, Serialize)]
pub struct StoryAreaPosition {
/// The radius of the rectangle corner rounding, as a percentage of the media width.
pub corner_radius_percentage: Float,
/// The height of the area's rectangle, as a percentage of the media height.
pub height_percentage: Float,
/// The clockwise rotation angle of the rectangle, in degrees; 0-360.
pub rotation_angle: Float,
/// The width of the area's rectangle, as a percentage of the media width.
pub width_percentage: Float,
/// The abscissa of the area's center, as a percentage of the media width.
pub x_percentage: Float,
/// The ordinate of the area's center, as a percentage of the media height.
pub y_percentage: Float,
}
/// Describes the type of a clickable area on a story.
#[derive(Clone, Debug, Deserialize, derive_more::From, PartialEq, PartialOrd, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum StoryAreaType {
/// An area pointing to an HTTP or tg:// link.
Link(StoryAreaTypeLink),
/// An area pointing to a location.
Location(StoryAreaTypeLocation),
/// An area pointing to a suggested reaction.
SuggestedReaction(StoryAreaTypeSuggestedReaction),
/// An area pointing to a unique gift.
UniqueGift(StoryAreaTypeUniqueGift),
/// An area containing weather information.
Weather(StoryAreaTypeWeather),
}
/// Describes a story area pointing to an HTTP or tg:// link.
///
/// Currently, a story can have up to 3 link areas.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct StoryAreaTypeLink {
/// HTTP or tg:// URL to be opened when the area is clicked.
pub url: String,
}
impl StoryAreaTypeLink {
/// Creates a new `StoryAreaTypeLink`.
///
/// # Arguments
///
/// * `url` - HTTP or tg:// URL to be opened when the area is clicked.
pub fn new<T>(url: T) -> Self
where
T: Into<String>,
{
Self { url: url.into() }
}
}
/// Describes a story area pointing to a location.
///
/// Currently, a story can have up to 10 location areas.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct StoryAreaTypeLocation {
/// Location latitude in degrees.
pub latitude: Float,
/// Location longitude in degrees.
pub longitude: Float,
/// Address of the location.
pub address: Option<LocationAddress>,
}
impl StoryAreaTypeLocation {
/// Creates a new `StoryAreaTypeLocation`.
///
/// # Arguments
///
/// * `latitude` - Location latitude in degrees.
/// * `longitude` - Location longitude in degrees.
pub fn new(latitude: Float, longitude: Float) -> Self {
Self {
latitude,
longitude,
address: None,
}
}
/// Sets a new address
///
/// # Arguments
///
/// * `value` - Address of the location.
pub fn with_address(mut self, value: LocationAddress) -> Self {
self.address = Some(value);
self
}
}
/// Describes a story area pointing to a suggested reaction.
///
/// Currently, a story can have up to 5 suggested reaction areas.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct StoryAreaTypeSuggestedReaction {
/// Type of the reaction.
pub reaction_type: ReactionType,
/// Whether the reaction area has a dark background.
pub is_dark: Option<bool>,
/// Whether reaction area corner is flipped.
pub is_flipped: Option<bool>,
}
impl StoryAreaTypeSuggestedReaction {
/// Creates a new `StoryAreaTypeSuggestedReaction`.
///
/// # Arguments
///
/// * `reaction_type` - Type of the reaction.
pub fn new(reaction_type: ReactionType) -> Self {
Self {
reaction_type,
is_dark: None,
is_flipped: None,
}
}
/// Sets a new value for the `is_dark` flag.
///
/// # Arguments
///
/// * `value` - Whether the reaction area has a dark background.
pub fn with_is_dark(mut self, value: bool) -> Self {
self.is_dark = Some(value);
self
}
/// Sets a new value for the `is_flipped` flag.
///
/// # Arguments
///
/// * `value` - Whether reaction area corner is flipped.
pub fn with_is_flipped(mut self, value: bool) -> Self {
self.is_flipped = Some(value);
self
}
}
/// Describes a story area pointing to a unique gift.
///
/// Currently, a story can have at most 1 unique gift area.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct StoryAreaTypeUniqueGift {
/// Unique name of the gift.
pub name: String,
}
impl StoryAreaTypeUniqueGift {
/// Creates a new `StoryAreaTypeUniqueGift`.
///
/// # Arguments
///
/// * `name` - Unique name of the gift.
pub fn new<T>(name: T) -> Self
where
T: Into<String>,
{
Self { name: name.into() }
}
}
/// Describes a story area containing weather information.
///
/// Currently, a story can have up to 3 weather areas.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct StoryAreaTypeWeather {
/// A color of the area background in the ARGB format.
pub background_color: Integer,
/// Emoji representing the weather.
pub emoji: String,
/// Temperature, in degree Celsius
pub temperature: Float,
}
impl StoryAreaTypeWeather {
/// Creates a new `StoryAreaTypeWeather`.
///
/// # Arguments
///
/// * `background_color` - A color of the area background in the ARGB format.
/// * `emoji` - Emoji representing the weather.
/// * `temperature` - Temperature, in degree Celsius.
pub fn new<T>(background_color: Integer, emoji: T, temperature: Float) -> Self
where
T: Into<String>,
{
Self {
background_color,
emoji: emoji.into(),
temperature,
}
}
}
/// Reposts a story on behalf of a business account from another business account.
///
/// Both business accounts must be managed by the same bot,
/// and the story on the source account must have been posted (or reposted) by the bot.
///
/// Requires the `can_manage_stories` business bot right for both business accounts.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct RepostStory {
active_period: Integer,
business_connection_id: String,
from_chat_id: Integer,
from_story_id: Integer,
post_to_chat_page: Option<bool>,
protect_content: Option<bool>,
}
impl RepostStory {
/// Creates a new `RepostStory`.
///
/// # Arguments
///
/// * `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.
/// * `business_connection_id` - Unique identifier of the business connection.
/// * `from_chat_id` - Unique identifier of the chat which posted the story that should be reposted.
/// * `from_story_id` - Unique identifier of the story that should be reposted.
pub fn new<T>(
active_period: Integer,
business_connection_id: T,
from_chat_id: Integer,
from_story_id: Integer,
) -> Self
where
T: Into<String>,
{
Self {
active_period,
business_connection_id: business_connection_id.into(),
from_chat_id,
from_story_id,
post_to_chat_page: None,
protect_content: None,
}
}
/// Sets a new value for the `post_to_chat_page` flag.
///
/// # Arguments
///
/// * `value` - Whether to keep the story accessible after it expires.
pub fn with_post_to_chat_page(mut self, value: bool) -> Self {
self.post_to_chat_page = Some(value);
self
}
/// Sets a new value for the `protect_content` flag.
///
/// # Arguments
///
/// * `value` - Whether the content of the story must be protected from forwarding and screenshotting.
pub fn with_protect_content(mut self, value: bool) -> Self {
self.protect_content = Some(value);
self
}
}
impl Method for RepostStory {
type Response = Story;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("repostStory", self)
}
}