1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Deserialize)]
5pub struct Update {
6 pub update_id: i64,
7 #[serde(flatten)]
8 pub kind: UpdateKind,
9}
10
11#[derive(Debug, Clone, Deserialize)]
13#[serde(rename_all = "snake_case")]
14#[allow(clippy::large_enum_variant)]
15pub enum UpdateKind {
16 Message(Message),
17 EditedMessage(Message),
18 CallbackQuery(CallbackQuery),
19 #[serde(other)]
20 Unknown,
21}
22
23#[derive(Debug, Clone, Deserialize)]
25pub struct Message {
26 pub message_id: i64,
27 pub from: Option<User>,
28 pub chat: Chat,
29 pub date: i64,
30 pub text: Option<String>,
31 pub entities: Option<Vec<MessageEntity>>,
32 pub reply_to_message: Option<Box<Message>>,
33}
34
35#[derive(Debug, Clone, Deserialize)]
37pub struct User {
38 pub id: i64,
39 pub is_bot: bool,
40 pub first_name: String,
41 pub last_name: Option<String>,
42 pub username: Option<String>,
43 pub language_code: Option<String>,
44}
45
46#[derive(Debug, Clone, Deserialize)]
48pub struct Chat {
49 pub id: i64,
50 #[serde(rename = "type")]
51 pub chat_type: ChatType,
52 pub title: Option<String>,
53 pub username: Option<String>,
54 pub first_name: Option<String>,
55 pub last_name: Option<String>,
56}
57
58#[derive(Debug, Clone, Deserialize)]
60#[serde(rename_all = "snake_case")]
61pub enum ChatType {
62 Private,
63 Group,
64 Supergroup,
65 Channel,
66}
67
68#[derive(Debug, Clone, Deserialize)]
70pub struct MessageEntity {
71 #[serde(rename = "type")]
72 pub entity_type: EntityType,
73 pub offset: i64,
74 pub length: i64,
75}
76
77#[derive(Debug, Clone, Deserialize)]
79#[serde(rename_all = "snake_case")]
80pub enum EntityType {
81 Mention,
82 Hashtag,
83 Cashtag,
84 BotCommand,
85 Url,
86 Email,
87 PhoneNumber,
88 Bold,
89 Italic,
90 Underline,
91 Strikethrough,
92 Spoiler,
93 Code,
94 Pre,
95 TextLink,
96 TextMention,
97 CustomEmoji,
98 #[serde(other)]
99 Unknown,
100}
101
102#[derive(Debug, Clone, Deserialize)]
104pub struct CallbackQuery {
105 pub id: String,
106 pub from: User,
107 pub message: Option<Message>,
108 pub inline_message_id: Option<String>,
109 pub chat_instance: String,
110 pub data: Option<String>,
111}
112
113#[derive(Debug, Clone, Serialize)]
115pub struct InlineKeyboardMarkup {
116 pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>,
117}
118
119#[derive(Debug, Clone, Serialize)]
121pub struct InlineKeyboardButton {
122 pub text: String,
123 #[serde(skip_serializing_if = "Option::is_none")]
124 pub url: Option<String>,
125 #[serde(skip_serializing_if = "Option::is_none")]
126 pub callback_data: Option<String>,
127}
128
129impl InlineKeyboardButton {
130 pub fn callback(text: impl Into<String>, data: impl Into<String>) -> Self {
131 Self {
132 text: text.into(),
133 url: None,
134 callback_data: Some(data.into()),
135 }
136 }
137
138 pub fn url(text: impl Into<String>, url: impl Into<String>) -> Self {
139 Self {
140 text: text.into(),
141 url: Some(url.into()),
142 callback_data: None,
143 }
144 }
145}
146
147#[derive(Debug, Clone, Serialize)]
149#[serde(untagged)]
150pub enum ReplyMarkup {
151 InlineKeyboard(InlineKeyboardMarkup),
152}
153
154#[derive(Debug, Clone, Serialize)]
156pub struct BotCommand {
157 pub command: String,
159 pub description: String,
161}
162
163impl BotCommand {
164 pub fn new(command: impl Into<String>, description: impl Into<String>) -> Self {
166 Self {
167 command: command.into(),
168 description: description.into(),
169 }
170 }
171}