telegrambot/api/
pin_chat_message.rs

1use std::ops::Not;
2
3use reqwest::Method;
4
5use crate::api::req::HttpReq;
6use crate::api::resp::JsonTrueToUnitResp;
7use crate::api::TGReq;
8use crate::errors::TGBotResult;
9
10/// Use this method to pin a message in a supergroup or a channel.
11/// The bot must be an administrator in the chat for this to work
12/// and must have the ‘can_pin_messages’ admin right in the supergroup
13/// or ‘can_edit_messages’ admin right in the channel.
14#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
15#[must_use = "requests do nothing unless sent"]
16pub struct PinChatMessage {
17  chat_id: i64,
18  message_id: i64,
19  #[serde(skip_serializing_if = "Not::not")]
20  disable_notification: bool,
21}
22
23
24impl TGReq for PinChatMessage {
25  type Resp = JsonTrueToUnitResp;
26
27  fn request(&self) -> TGBotResult<HttpReq> {
28    HttpReq::json_req(Method::POST, "pinChatMessage", self)
29  }
30}
31
32
33impl PinChatMessage {
34  pub fn new(chat: i64, message: i64) -> Self{
35    Self {
36      chat_id: chat,
37      message_id: message,
38      disable_notification: false,
39    }
40  }
41
42  pub fn disable_notification(&mut self) -> &mut Self {
43    self.disable_notification = true;
44    self
45  }
46}