1use layer_tl_types as tl;
17
18#[derive(Clone)]
22pub struct Button {
23 inner: tl::enums::KeyboardButton,
24}
25
26impl Button {
27 pub fn callback(text: impl Into<String>, data: impl Into<Vec<u8>>) -> Self {
29 Self {
30 inner: tl::enums::KeyboardButton::Callback(
31 tl::types::KeyboardButtonCallback {
32 requires_password: false,
33 text: text.into(),
34 data: data.into(),
35 style: None,
36 },
37 ),
38 }
39 }
40
41 pub fn url(text: impl Into<String>, url: impl Into<String>) -> Self {
43 Self {
44 inner: tl::enums::KeyboardButton::Url(
45 tl::types::KeyboardButtonUrl {
46 text: text.into(),
47 url: url.into(),
48 style: None,
49 },
50 ),
51 }
52 }
53
54 pub fn url_auth(text: impl Into<String>, url: impl Into<String>, fwd_text: Option<String>, bot: tl::enums::InputUser) -> Self {
56 Self {
57 inner: tl::enums::KeyboardButton::InputKeyboardButtonUrlAuth(
58 tl::types::InputKeyboardButtonUrlAuth {
59 request_write_access: false,
60 text: text.into(),
61 fwd_text,
62 url: url.into(),
63 bot,
64 style: None,
65 },
66 ),
67 }
68 }
69
70 pub fn switch_inline(text: impl Into<String>, query: impl Into<String>) -> Self {
72 Self {
73 inner: tl::enums::KeyboardButton::SwitchInline(
74 tl::types::KeyboardButtonSwitchInline {
75 same_peer: true,
76 peer_types: None,
77 text: text.into(),
78 query: query.into(),
79 style: None,
80 },
81 ),
82 }
83 }
84
85 pub fn text(label: impl Into<String>) -> Self {
87 Self {
88 inner: tl::enums::KeyboardButton::KeyboardButton(
89 tl::types::KeyboardButton { text: label.into(), style: None },
90 ),
91 }
92 }
93
94 pub fn into_raw(self) -> tl::enums::KeyboardButton {
96 self.inner
97 }
98}
99
100#[derive(Clone, Default)]
117pub struct InlineKeyboard {
118 rows: Vec<Vec<Button>>,
119}
120
121impl InlineKeyboard {
122 pub fn new() -> Self {
124 Self::default()
125 }
126
127 pub fn row(mut self, buttons: impl IntoIterator<Item = Button>) -> Self {
129 self.rows.push(buttons.into_iter().collect());
130 self
131 }
132
133 pub fn into_markup(self) -> tl::enums::ReplyMarkup {
135 let rows = self.rows.into_iter().map(|row| {
136 tl::enums::KeyboardButtonRow::KeyboardButtonRow(
137 tl::types::KeyboardButtonRow {
138 buttons: row.into_iter().map(Button::into_raw).collect(),
139 },
140 )
141 }).collect();
142
143 tl::enums::ReplyMarkup::ReplyInlineMarkup(
144 tl::types::ReplyInlineMarkup { rows }
145 )
146 }
147}
148
149impl From<InlineKeyboard> for tl::enums::ReplyMarkup {
150 fn from(kb: InlineKeyboard) -> Self {
151 kb.into_markup()
152 }
153}
154
155#[derive(Clone, Default)]
159pub struct ReplyKeyboard {
160 rows: Vec<Vec<Button>>,
161 resize: bool,
162 single_use: bool,
163 selective: bool,
164}
165
166impl ReplyKeyboard {
167 pub fn new() -> Self { Self::default() }
169
170 pub fn row(mut self, buttons: impl IntoIterator<Item = Button>) -> Self {
172 self.rows.push(buttons.into_iter().collect());
173 self
174 }
175
176 pub fn resize(mut self) -> Self { self.resize = true; self }
178
179 pub fn single_use(mut self) -> Self { self.single_use = true; self }
181
182 pub fn selective(mut self) -> Self { self.selective = true; self }
184
185 pub fn into_markup(self) -> tl::enums::ReplyMarkup {
187 let rows = self.rows.into_iter().map(|row| {
188 tl::enums::KeyboardButtonRow::KeyboardButtonRow(
189 tl::types::KeyboardButtonRow {
190 buttons: row.into_iter().map(Button::into_raw).collect(),
191 },
192 )
193 }).collect();
194
195 tl::enums::ReplyMarkup::ReplyKeyboardMarkup(
196 tl::types::ReplyKeyboardMarkup {
197 resize: self.resize,
198 single_use: self.single_use,
199 selective: self.selective,
200 persistent: false,
201 rows,
202 placeholder: None,
203 }
204 )
205 }
206}
207
208impl From<ReplyKeyboard> for tl::enums::ReplyMarkup {
209 fn from(kb: ReplyKeyboard) -> Self {
210 kb.into_markup()
211 }
212}