botx_api/bot/models/command_body.rs
1use serde::{Serialize, Deserialize};
2
3// #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
4// #[serde(untagged)]
5// pub enum CommandBody {
6// /// Событие отправляется при создание чата
7// #[serde(rename(serialize = "system:chat_created", deserialize = "system:chat_created"))]
8// ChatCreated,
9
10// /// Событие отправляется при добавление мемберов в чат
11// #[serde(rename(serialize = "system:added_to_chat", deserialize = "system:added_to_chat"))]
12// AddedToChat,
13
14// /// Событие отправляется при удалении администратором участников чата
15// #[serde(rename(serialize = "system:deleted_from_chat", deserialize = "system:deleted_from_chat"))]
16// DeletedFromChat,
17
18// /// Событие отправляется при выходе участников из чата
19// #[serde(rename(serialize = "system:left_from_chat", deserialize = "system:left_from_chat"))]
20// LeftFromChat,
21
22// /// Событие отправляется клиентом при взаимодействии со smartapp приложением
23// #[serde(rename(serialize = "system:smartapp_event", deserialize = "system:smartapp_event"))]
24// SmartappEvent,
25
26// /// Событие отправляется ботом при взаимодействие с другими ботами
27// #[serde(rename(serialize = "system:internal_bot_notification", deserialize = "system:internal_bot_notification"))]
28// InternalBotNotification,
29
30// /// Событие отправляется при успешном логине пользователя на CTS
31// #[serde(rename(serialize = "system:cts_login", deserialize = "system:cts_login"))]
32// CtsLogin,
33
34// /// Событие отправляется при успешном выходе пользователя с CTS
35// #[serde(rename(serialize = "system:cts_logout", deserialize = "system:cts_logout"))]
36// CtsLogout,
37
38// Text(String),
39// Other(serde_json::Value),
40// }
41
42// impl CommandBody {
43// pub fn unwrap_text(&self) -> &String {
44// match self {
45// CommandBody::Text(data) => data,
46// _ => panic!("Unexpected command body")
47// }
48// }
49
50// pub fn unwrap_other(&self) -> &serde_json::Value {
51// match self {
52// CommandBody::Other(data) => data,
53// _ => panic!("Unexpected command body")
54// }
55// }
56
57// pub fn is_added_to_chat(&self) -> bool {
58// matches!(self, CommandBody::AddedToChat)
59// }
60
61// pub fn is_chat_created(&self) -> bool {
62// matches!(self, CommandBody::ChatCreated)
63// }
64
65// pub fn is_deleted_from_chat(&self) -> bool {
66// matches!(self, CommandBody::DeletedFromChat)
67// }
68
69// pub fn is_left_from_chat(&self) -> bool {
70// matches!(self, CommandBody::LeftFromChat)
71// }
72
73// pub fn is_smartapp_event(&self) -> bool {
74// matches!(self, CommandBody::SmartappEvent)
75// }
76
77// pub fn is_internal_bot_notification(&self) -> bool {
78// matches!(self, CommandBody::InternalBotNotification)
79// }
80
81// pub fn is_cts_login(&self) -> bool {
82// matches!(self, CommandBody::CtsLogin)
83// }
84
85// pub fn is_cts_logout(&self) -> bool {
86// matches!(self, CommandBody::CtsLogout)
87// }
88
89// pub fn is_text(&self) -> bool {
90// match self {
91// CommandBody::Text(_) => true,
92// _ => false
93// }
94// }
95
96// pub fn is_other(&self) -> bool {
97// match self {
98// CommandBody::Other(_) => true,
99// _ => false
100// }
101// }
102// }
103
104#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
105#[serde(untagged)]
106pub enum CommandBody<TBody> {
107 /// Событие отправляется при создание чата
108 #[serde(rename(serialize = "system:chat_created", deserialize = "system:chat_created"))]
109 ChatCreated,
110
111 /// Событие отправляется при добавление мемберов в чат
112 #[serde(rename(serialize = "system:added_to_chat", deserialize = "system:added_to_chat"))]
113 AddedToChat,
114
115 /// Событие отправляется при удалении администратором участников чата
116 #[serde(rename(serialize = "system:deleted_from_chat", deserialize = "system:deleted_from_chat"))]
117 DeletedFromChat,
118
119 /// Событие отправляется при выходе участников из чата
120 #[serde(rename(serialize = "system:left_from_chat", deserialize = "system:left_from_chat"))]
121 LeftFromChat,
122
123 /// Событие отправляется клиентом при взаимодействии со smartapp приложением
124 #[serde(rename(serialize = "system:smartapp_event", deserialize = "system:smartapp_event"))]
125 SmartappEvent,
126
127 /// Событие отправляется ботом при взаимодействие с другими ботами
128 #[serde(rename(serialize = "system:internal_bot_notification", deserialize = "system:internal_bot_notification"))]
129 InternalBotNotification,
130
131 /// Событие отправляется при успешном логине пользователя на CTS
132 #[serde(rename(serialize = "system:cts_login", deserialize = "system:cts_login"))]
133 CtsLogin,
134
135 /// Событие отправляется при успешном выходе пользователя с CTS
136 #[serde(rename(serialize = "system:cts_logout", deserialize = "system:cts_logout"))]
137 CtsLogout,
138
139 Body(TBody),
140}
141
142impl<TBody> CommandBody<TBody> {
143 pub fn unwrap_body(&self) -> &TBody {
144 match self {
145 CommandBody::Body(data) => data,
146 _ => panic!("Unexpected command body")
147 }
148 }
149
150 pub fn is_added_to_chat(&self) -> bool {
151 matches!(self, CommandBody::AddedToChat)
152 }
153
154 pub fn is_chat_created(&self) -> bool {
155 matches!(self, CommandBody::ChatCreated)
156 }
157
158 pub fn is_deleted_from_chat(&self) -> bool {
159 matches!(self, CommandBody::DeletedFromChat)
160 }
161
162 pub fn is_left_from_chat(&self) -> bool {
163 matches!(self, CommandBody::LeftFromChat)
164 }
165
166 pub fn is_smartapp_event(&self) -> bool {
167 matches!(self, CommandBody::SmartappEvent)
168 }
169
170 pub fn is_internal_bot_notification(&self) -> bool {
171 matches!(self, CommandBody::InternalBotNotification)
172 }
173
174 pub fn is_cts_login(&self) -> bool {
175 matches!(self, CommandBody::CtsLogin)
176 }
177
178 pub fn is_cts_logout(&self) -> bool {
179 matches!(self, CommandBody::CtsLogout)
180 }
181
182 // pub fn is_text(&self) -> bool {
183 // match self {
184 // CommandBody::Text(_) => true,
185 // _ => false
186 // }
187 // }
188
189 pub fn is_body(&self) -> bool {
190 match self {
191 CommandBody::Body(_) => true,
192 _ => false
193 }
194 }
195}