1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use serde::{Deserialize, Serialize};

use crate::{ChatLocation, ChatPhoto, Message};

/// This object represents a chat.
#[derive(Debug, Serialize, Deserialize)]
pub struct Chat {
    /// Unique identifier for this chat.
    ///
    /// This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
    /// But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
    pub id: i64,

    /// Type of chat,
    /// can be either “private”, “group”, “supergroup” or “channel”
    #[serde(flatten)]
    pub kind: ChatKind,

    /// Title, for supergroups, channels and group chats
    pub title: Option<String>,

    /// Username, for private chats, supergroups and channels if available
    pub username: Option<String>,

    /// The user chat with in a private chat
    #[serde(flatten)]
    pub chat_user: ChatUser,

    /// Chat photo. Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub photo: Option<ChatPhoto>,

    /// *True*, if privacy settings of the other party in the private chat allows to use `tg://user?id=<user_id>` links only in chats with the user.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    #[serde(default, skip_serializing_if = "crate::util::is_false")]
    pub has_private_forwards: bool,

    /// *True*, if the privacy settings of the other party restrict sending voice and video note messages in the private chat.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    #[serde(default, skip_serializing_if = "crate::util::is_false")]
    pub has_restricted_voice_and_video_messages: bool,

    /// *True*, if users need to join the supergroup before they can send messages.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    #[serde(default, skip_serializing_if = "crate::util::is_false")]
    pub join_to_send_messages: bool,

    /// *True*, if all users directly joining the supergroup need to be approved by supergroup administrators.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    #[serde(default, skip_serializing_if = "crate::util::is_false")]
    pub join_by_request: bool,

    /// Description, for groups, supergroups and channel chats.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub description: Option<String>,

    /// Primary invite link, for groups, supergroups and channel chats.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub invite_link: Option<String>,

    /// The most recent pinned message (by sending date).
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub pinned_message: Option<Box<Message>>,

    /// Default chat member permissions, for groups and supergroups.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub permissions: Option<ChatPermissions>,

    /// For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user; in seconds.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub slow_mode_delay: Option<i32>,

    /// The time after which all messages sent to the chat will be automatically deleted; in seconds.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub message_auto_delete_time: Option<i32>,

    /// *True*, if messages from the chat can't be forwarded to other chats.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    #[serde(default, skip_serializing_if = "crate::util::is_false")]
    pub has_protected_content: bool,

    /// For supergroups, name of group sticker set.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub sticker_set_name: Option<String>,

    /// *True*, if the bot can change the group sticker set.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    #[serde(default, skip_serializing_if = "crate::util::is_false")]
    pub can_set_sticker_set: bool,

    /// Unique identifier for the linked chat,
    /// i.e. the discussion group identifier for a channel and vice versa; for supergroups and channel chats.
    /// This identifier may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it.
    /// But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub linked_chat_id: Option<i64>,

    /// For supergroups, the location to which the supergroup is connected.
    /// Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub location: Option<ChatLocation>,
}

/// This object respresents an information about user from private chat
#[derive(Debug, Serialize, Deserialize)]
pub struct ChatUser {
    /// First name of the other party in a private chat
    pub first_name: String,

    /// Last name of the other party in a private chat
    pub last_name: Option<String>,

    /// Bio of the other party in a private chat. Returned only in [getChat](https://core.telegram.org/bots/api#getchat).
    pub bio: Option<String>,
}

/// The kind of chat
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum ChatKind {
    /// Private chat
    Private,
    /// Group
    Group,
    /// Supergroup
    Supergroup,
    /// Channel
    Channel,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ChatPermissions {}