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
use serde::{Deserialize, Serialize};
/// Rich formatted message.
/// # Documentation
/// <https://core.telegram.org/bots/api#richmessage>
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RichMessage {
/// Content of the message
pub blocks: Box<[crate::types::RichBlock]>,
/// `true`, if the rich message must be shown right-to-left
#[serde(skip_serializing_if = "Option::is_none")]
pub is_rtl: Option<bool>,
}
impl RichMessage {
/// Creates a new `RichMessage`.
///
/// # Arguments
/// * `blocks` - Content of the message
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new<T0Item: Into<crate::types::RichBlock>, T0: IntoIterator<Item = T0Item>>(
blocks: T0,
) -> Self {
Self {
blocks: blocks.into_iter().map(Into::into).collect(),
is_rtl: None,
}
}
/// Content of the message
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn blocks<T: Into<Box<[crate::types::RichBlock]>>>(mut self, val: T) -> Self {
self.blocks = self
.blocks
.into_vec()
.into_iter()
.chain(val.into())
.collect();
self
}
/// Content of the message
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn block<T: Into<crate::types::RichBlock>>(mut self, val: T) -> Self {
self.blocks = self
.blocks
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect();
self
}
/// `true`, if the rich message must be shown right-to-left
#[must_use]
pub fn is_rtl<T: Into<bool>>(mut self, val: T) -> Self {
self.is_rtl = Some(val.into());
self
}
/// `true`, if the rich message must be shown right-to-left
#[must_use]
pub fn is_rtl_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.is_rtl = val.map(Into::into);
self
}
}