1use serde::{Deserialize, Serialize};
2
3use crate::{
4 api::{Method, Payload},
5 types::{Integer, WebAppInfo},
6};
7
8#[cfg(test)]
9mod tests;
10
11#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
17#[serde(from = "MenuButtonRaw", into = "MenuButtonRaw")]
18pub enum MenuButton {
19 Commands,
21 Default,
23 WebApp(MenuButtonWebApp),
25}
26
27#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
29pub struct MenuButtonWebApp {
30 pub text: String,
32 pub web_app: WebAppInfo,
39}
40
41impl MenuButtonWebApp {
42 pub fn new<T>(text: T, web_app: WebAppInfo) -> Self
49 where
50 T: Into<String>,
51 {
52 Self {
53 text: text.into(),
54 web_app,
55 }
56 }
57}
58
59#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
60#[serde(rename_all = "snake_case", tag = "type")]
61enum MenuButtonRaw {
62 Commands {},
63 Default {},
64 WebApp(MenuButtonWebApp),
65}
66
67impl From<MenuButtonRaw> for MenuButton {
68 fn from(value: MenuButtonRaw) -> Self {
69 match value {
70 MenuButtonRaw::Commands {} => Self::Commands,
71 MenuButtonRaw::Default {} => Self::Default,
72 MenuButtonRaw::WebApp(value) => Self::WebApp(value),
73 }
74 }
75}
76
77impl From<MenuButton> for MenuButtonRaw {
78 fn from(value: MenuButton) -> Self {
79 match value {
80 MenuButton::Commands => Self::Commands {},
81 MenuButton::Default => Self::Default {},
82 MenuButton::WebApp(value) => Self::WebApp(value),
83 }
84 }
85}
86
87#[serde_with::skip_serializing_none]
89#[derive(Clone, Debug, Default, Serialize)]
90pub struct GetChatMenuButton {
91 chat_id: Option<Integer>,
92}
93
94impl GetChatMenuButton {
95 pub fn with_chat_id(mut self, value: Integer) -> Self {
103 self.chat_id = Some(value);
104 self
105 }
106}
107
108impl Method for GetChatMenuButton {
109 type Response = MenuButton;
110
111 fn into_payload(self) -> Payload {
112 Payload::json("getChatMenuButton", self)
113 }
114}
115
116#[serde_with::skip_serializing_none]
118#[derive(Clone, Debug, Default, Serialize)]
119pub struct SetChatMenuButton {
120 chat_id: Option<Integer>,
121 menu_button: Option<MenuButton>,
122}
123
124impl SetChatMenuButton {
125 pub fn chat_id(mut self, chat_id: Integer) -> Self {
133 self.chat_id = Some(chat_id);
134 self
135 }
136
137 pub fn menu_button(mut self, value: MenuButton) -> Self {
143 self.menu_button = Some(value);
144 self
145 }
146}
147
148impl Method for SetChatMenuButton {
149 type Response = bool;
150
151 fn into_payload(self) -> Payload {
152 Payload::json("setChatMenuButton", self)
153 }
154}