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
use serde::{Deserialize, Serialize};
use crate::entities::{
force_reply::ForceReply, inline_keyboard_button::InlineKeyboardButton,
inline_keyboard_markup::InlineKeyboardMarkup, keyboard_button::KeyboardButton,
reply_keyboard_markup::ReplyKeyboardMarkup, reply_keyboard_remove::ReplyKeyboardRemove,
};
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum ReplyMarkup {
Keyboard(ReplyKeyboardMarkup),
Inline(InlineKeyboardMarkup),
ForceReply(ForceReply),
Remove(ReplyKeyboardRemove),
}
impl From<ReplyKeyboardMarkup> for ReplyMarkup {
fn from(value: ReplyKeyboardMarkup) -> Self {
Self::Keyboard(value)
}
}
impl From<InlineKeyboardMarkup> for ReplyMarkup {
fn from(value: InlineKeyboardMarkup) -> Self {
Self::Inline(value)
}
}
impl From<ForceReply> for ReplyMarkup {
fn from(value: ForceReply) -> Self {
Self::ForceReply(value)
}
}
impl From<ReplyKeyboardRemove> for ReplyMarkup {
fn from(value: ReplyKeyboardRemove) -> Self {
Self::Remove(value)
}
}
impl ReplyMarkup {
///Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot's message and tapped 'Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice [privacy mode](https://core.telegram.org/bots/features#privacy-mode).
///API Reference: [link](https://core.telegram.org/bots/api/#forcereply)
pub fn force_reply(
input_field_placeholder: Option<impl Into<String>>,
selective: bool,
) -> Self {
Self::ForceReply(ForceReply {
force_reply: true,
input_field_placeholder: input_field_placeholder.map(Into::into),
selective,
})
}
///This object represents a [custom keyboard](https://core.telegram.org/bots/features#keyboards) with reply options (see [Introduction to bots](https://core.telegram.org/bots/features#keyboards) for details and examples).
///API Reference: [link](https://core.telegram.org/bots/api/#replykeyboardmarkup)
pub fn keyboard(
keyboard: impl Into<Vec<Vec<KeyboardButton>>>,
is_persistent: bool,
resize_keyboard: bool,
one_time_keyboard: bool,
input_field_placeholder: Option<impl Into<String>>,
selective: bool,
) -> Self {
Self::Keyboard(ReplyKeyboardMarkup {
keyboard: keyboard.into(),
is_persistent,
resize_keyboard,
one_time_keyboard,
input_field_placeholder: input_field_placeholder.map(Into::into),
selective,
})
}
///This object represents an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards) that appears right next to the message it belongs to.
///API Reference: [link](https://core.telegram.org/bots/api/#inlinekeyboardmarkup)
pub fn inline(keyboard: impl Into<Vec<Vec<InlineKeyboardButton>>>) -> Self {
Self::Inline(InlineKeyboardMarkup {
inline_keyboard: keyboard.into(),
})
}
///Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see [ReplyKeyboardMarkup](https://core.telegram.org/bots/api/#replykeyboardmarkup)).
///API Reference: [link](https://core.telegram.org/bots/api/#replykeyboardremove)
pub const fn remove(remove_keyboard: bool, selective: bool) -> Self {
Self::Remove(ReplyKeyboardRemove {
remove_keyboard,
selective,
})
}
}