tgbot/types/definitions/
menu.rs1use serde::{Deserialize, Serialize};
2
3use crate::{
4 api::{Method, Payload},
5 types::{Integer, WebAppInfo},
6};
7
8#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
14#[serde(from = "MenuButtonRaw", into = "MenuButtonRaw")]
15pub enum MenuButton {
16 Commands,
18 Default,
20 WebApp(MenuButtonWebApp),
22}
23
24#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
26pub struct MenuButtonWebApp {
27 pub text: String,
29 pub web_app: WebAppInfo,
36}
37
38impl MenuButtonWebApp {
39 pub fn new<T>(text: T, web_app: WebAppInfo) -> Self
46 where
47 T: Into<String>,
48 {
49 Self {
50 text: text.into(),
51 web_app,
52 }
53 }
54}
55
56#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
57#[serde(rename_all = "snake_case", tag = "type")]
58enum MenuButtonRaw {
59 Commands {},
60 Default {},
61 WebApp(MenuButtonWebApp),
62}
63
64impl From<MenuButtonRaw> for MenuButton {
65 fn from(value: MenuButtonRaw) -> Self {
66 match value {
67 MenuButtonRaw::Commands {} => Self::Commands,
68 MenuButtonRaw::Default {} => Self::Default,
69 MenuButtonRaw::WebApp(value) => Self::WebApp(value),
70 }
71 }
72}
73
74impl From<MenuButton> for MenuButtonRaw {
75 fn from(value: MenuButton) -> Self {
76 match value {
77 MenuButton::Commands => Self::Commands {},
78 MenuButton::Default => Self::Default {},
79 MenuButton::WebApp(value) => Self::WebApp(value),
80 }
81 }
82}
83
84#[serde_with::skip_serializing_none]
86#[derive(Clone, Debug, Default, Serialize)]
87pub struct GetChatMenuButton {
88 chat_id: Option<Integer>,
89}
90
91impl GetChatMenuButton {
92 pub fn with_chat_id(mut self, value: Integer) -> Self {
100 self.chat_id = Some(value);
101 self
102 }
103}
104
105impl Method for GetChatMenuButton {
106 type Response = MenuButton;
107
108 fn into_payload(self) -> Payload {
109 Payload::json("getChatMenuButton", self)
110 }
111}
112
113#[serde_with::skip_serializing_none]
115#[derive(Clone, Debug, Default, Serialize)]
116pub struct SetChatMenuButton {
117 chat_id: Option<Integer>,
118 menu_button: Option<MenuButton>,
119}
120
121impl SetChatMenuButton {
122 pub fn chat_id(mut self, chat_id: Integer) -> Self {
130 self.chat_id = Some(chat_id);
131 self
132 }
133
134 pub fn menu_button(mut self, value: MenuButton) -> Self {
140 self.menu_button = Some(value);
141 self
142 }
143}
144
145impl Method for SetChatMenuButton {
146 type Response = bool;
147
148 fn into_payload(self) -> Payload {
149 Payload::json("setChatMenuButton", self)
150 }
151}