server_watchdog/infrastructure/client/telegram/
dto.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug)]
4pub struct SendMessageDto {
5 chat_id: String,
6 text: String,
7 #[serde(skip_serializing_if = "Option::is_none")]
8 reply_markup: Option<ReplyMarkup>
9}
10
11#[derive(Serialize, Deserialize, Debug)]
12pub struct GetUpdateDto {
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub offset: Option<i64>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 timeout: Option<i32>,
17}
18
19impl GetUpdateDto {
20 pub fn new(offset: i64) -> Self {
21 Self {
22 offset: Some(offset),
23 timeout: Some(30)
24 }
25 }
26}
27
28#[derive(Serialize, Deserialize, Debug)]
29pub struct ReplyMarkup {
30 pub inline_keyboard: Vec<InlineKeyboardButton>
31}
32
33#[derive(Serialize, Deserialize, Debug)]
34pub struct InlineKeyboardButton {
35 pub text: String,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 pub url: Option<String>,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub callback_data: Option<String>
40}
41
42#[derive(Deserialize, Debug)]
43pub struct TelegramResponse<T> {
44 pub ok: bool,
45 pub result: T,
46 pub error_code: Option<i16>,
47 pub description: Option<String>,
48}
49
50impl SendMessageDto {
51 pub fn new(chat_id: &str, text: &str, reply_markup: Option<ReplyMarkup>) -> Self {
52 Self {
53 chat_id: chat_id.to_string(),
54 text: text.to_string(),
55 reply_markup
56 }
57 }
58}
59
60#[derive(Serialize, Deserialize, Debug)]
61pub struct Message {
62 pub message_id: i64,
63 #[serde(skip_serializing_if = "Option::is_none")]
64 pub message_thread_id: Option<i64>,
65 pub from: User,
66 pub date: i64,
67 pub chat: Chat,
68 #[serde(skip_serializing_if = "Option::is_none")]
69 pub text: Option<String>
70}
71
72#[derive(Serialize, Deserialize, Debug)]
73pub struct Update {
74 pub update_id: i64,
75 pub message: Option<Message>,
76 pub edited_message: Option<Message>,
77 pub callback_query: Option<CallbackQuery>
78}
79
80#[derive(Serialize, Deserialize, Debug)]
81pub struct CallbackQuery {
82 pub id: String,
83 pub from: User,
84 pub message: Option<Message>,
85 pub inline_message_id: Option<String>,
86 pub chat_instance: String,
87 pub data: Option<String>,
88 pub game_short_name: Option<String>
89}
90
91#[derive(Serialize, Deserialize, Debug)]
92pub struct Chat {
93 pub id: i64,
94 pub r#type: String,
95 pub title: Option<String>,
96 pub username: Option<String>,
97 pub first_name: Option<String>,
98 pub last_name: Option<String>,
99 pub is_forum: Option<bool>,
100 pub is_direct_messages: Option<bool>
101}
102
103#[derive(Serialize, Deserialize, Debug)]
104pub struct User {
105 id: i64,
106 is_bot: bool,
107 first_name: String
108}