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