tgbot/types/chat/message/mod.rs
1use serde::Serialize;
2
3use crate::{
4 api::{Method, Payload},
5 types::{ChatId, Integer},
6};
7
8#[cfg(test)]
9mod tests;
10
11/// Adds a message to a list of pinned messages in a chat.
12///
13/// If the chat is not a private chat, the bot must be an administrator
14/// in the chat for this to work and must have the `can_pin_messages`
15/// admin right in a supergroup or `can_edit_messages` admin right in a channel.
16#[serde_with::skip_serializing_none]
17#[derive(Clone, Debug, Serialize)]
18pub struct PinChatMessage {
19 chat_id: ChatId,
20 message_id: Integer,
21 business_connection_id: Option<String>,
22 disable_notification: Option<bool>,
23}
24
25impl PinChatMessage {
26 /// Creates a new `PinChatMessage`
27 ///
28 /// # Arguments
29 ///
30 /// * `chat_id` - Unique identifier of the target chat.
31 /// * `message_id` - Identifier of a message to pin.
32 pub fn new<T>(chat_id: T, message_id: Integer) -> Self
33 where
34 T: Into<ChatId>,
35 {
36 PinChatMessage {
37 chat_id: chat_id.into(),
38 message_id,
39 business_connection_id: None,
40 disable_notification: None,
41 }
42 }
43
44 /// Sets a new business connection ID.
45 ///
46 /// # Arguments
47 ///
48 /// * `value` - Unique identifier of the business connection
49 /// on behalf of which the message will be pinned.
50 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
51 where
52 T: Into<String>,
53 {
54 self.business_connection_id = Some(value.into());
55 self
56 }
57
58 /// Sets a new value for the `disable_notification` flag.
59 ///
60 /// # Arguments
61 ///
62 /// * `value` - Indicates whether to notify all chat members about the new pinned message;
63 /// notifications are always disabled in channels and private chats.
64 pub fn with_disable_notification(mut self, value: bool) -> Self {
65 self.disable_notification = Some(value);
66 self
67 }
68}
69
70impl Method for PinChatMessage {
71 type Response = bool;
72
73 fn into_payload(self) -> Payload {
74 Payload::json("pinChatMessage", self)
75 }
76}
77
78/// Removes a message from a list of pinned messages in a chat.
79///
80/// If the chat is not a private chat, the bot must be an administrator
81/// in the chat for this to work and must have the `can_pin_messages`
82/// admin right in a supergroup or `can_edit_messages` admin right in a channel.
83#[serde_with::skip_serializing_none]
84#[derive(Clone, Debug, Serialize)]
85pub struct UnpinChatMessage {
86 chat_id: ChatId,
87 business_connection_id: Option<String>,
88 message_id: Option<Integer>,
89}
90
91impl UnpinChatMessage {
92 /// Creates a new `UnpinChatMessage`.
93 ///
94 /// # Arguments
95 ///
96 /// * `chat_id` - Unique identifier of the target chat.
97 pub fn new<T>(chat_id: T) -> Self
98 where
99 T: Into<ChatId>,
100 {
101 UnpinChatMessage {
102 chat_id: chat_id.into(),
103 business_connection_id: None,
104 message_id: None,
105 }
106 }
107
108 /// Sets a new business connection ID.
109 ///
110 /// # Arguments
111 ///
112 /// * `value` - Unique identifier of the business connection
113 /// on behalf of which the message will be unpinned.
114 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
115 where
116 T: Into<String>,
117 {
118 self.business_connection_id = Some(value.into());
119 self
120 }
121
122 /// Sets a new message ID.
123 ///
124 /// # Arguments
125 ///
126 /// * `value` - Identifier of a message to unpin.
127 ///
128 /// If not specified, the most recent pinned message (by sending date) will be unpinned.
129 pub fn with_message_id(mut self, value: Integer) -> Self {
130 self.message_id = Some(value);
131 self
132 }
133}
134
135impl Method for UnpinChatMessage {
136 type Response = bool;
137
138 fn into_payload(self) -> Payload {
139 Payload::json("unpinChatMessage", self)
140 }
141}
142
143/// Clears a list of pinned messages in a chat.
144///
145/// If the chat is not a private chat, the bot must be an administrator
146/// in the chat for this to work and must have the `can_pin_messages`
147/// admin right in a supergroup or `can_edit_messages` admin right in a channel.
148#[derive(Clone, Debug, Serialize)]
149pub struct UnpinAllChatMessages {
150 chat_id: ChatId,
151}
152
153impl UnpinAllChatMessages {
154 /// Creates a new `UnpinAllChatMessages`.
155 ///
156 /// # Arguments
157 ///
158 /// * `chat_id` - Unique identifier of the target chat.
159 pub fn new<T>(chat_id: T) -> Self
160 where
161 T: Into<ChatId>,
162 {
163 UnpinAllChatMessages {
164 chat_id: chat_id.into(),
165 }
166 }
167}
168
169impl Method for UnpinAllChatMessages {
170 type Response = bool;
171
172 fn into_payload(self) -> Payload {
173 Payload::json("unpinAllChatMessages", self)
174 }
175}