tg_flows/types/
reply_markup.rs1use derive_more::From;
2use serde::{Deserialize, Serialize};
3
4use crate::types::{
5 ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, KeyboardMarkup,
6 KeyboardRemove,
7};
8
9#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, From)]
10#[serde(untagged)]
11pub enum ReplyMarkup {
12 InlineKeyboard(InlineKeyboardMarkup),
13 Keyboard(KeyboardMarkup),
14 KeyboardRemove(KeyboardRemove),
15 ForceReply(ForceReply),
16}
17
18impl ReplyMarkup {
19 pub fn inline_kb<I>(inline_keyboard: I) -> Self
26 where
27 I: IntoIterator,
28 I::Item: IntoIterator<Item = InlineKeyboardButton>,
29 {
30 Self::InlineKeyboard(InlineKeyboardMarkup::new(inline_keyboard))
31 }
32
33 pub fn keyboard<K>(keyboard: K) -> Self
40 where
41 K: IntoIterator,
42 K::Item: IntoIterator<Item = KeyboardButton>,
43 {
44 Self::Keyboard(KeyboardMarkup::new(keyboard))
45 }
46
47 #[must_use]
54 pub fn kb_remove() -> Self {
55 Self::KeyboardRemove(KeyboardRemove::new())
56 }
57
58 #[must_use]
64 pub fn force_reply() -> Self {
65 Self::ForceReply(ForceReply::new())
66 }
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn inline_keyboard_markup() {
75 let data = InlineKeyboardMarkup::default();
76 let expected = ReplyMarkup::InlineKeyboard(data.clone());
77 let actual: ReplyMarkup = data.into();
78 assert_eq!(actual, expected)
79 }
80}