telegram_bot_raw/requests/
delete_message.rs

1use crate::requests::*;
2use crate::types::*;
3
4// Use this method to delete a message.
5// A message can only be deleted if it was sent less than 48 hours ago.
6// Any such recently sent outgoing message may be deleted.
7// Additionally, if the bot is an administrator in a group chat, it can delete any message.
8// If the bot is an administrator in a supergroup, it can delete messages from any
9// other user and service messages about people joining or leaving the
10// group (other types of service messages may only be removed by the group creator).
11// In channels, bots can only remove their own messages.
12#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
13#[must_use = "requests do nothing unless sent"]
14pub struct DeleteMessage {
15    chat_id: ChatRef,
16    message_id: MessageId,
17}
18
19impl Request for DeleteMessage {
20    type Type = JsonRequestType<Self>;
21    type Response = JsonTrueToUnitResponse;
22
23    fn serialize(&self) -> Result<HttpRequest, Error> {
24        Self::Type::serialize(RequestUrl::method("deleteMessage"), self)
25    }
26}
27
28impl DeleteMessage {
29    pub fn new<C, M>(chat: C, message_id: M) -> Self
30    where
31        C: ToChatRef,
32        M: ToMessageId,
33    {
34        DeleteMessage {
35            chat_id: chat.to_chat_ref(),
36            message_id: message_id.to_message_id(),
37        }
38    }
39}
40
41/// Delete messages..
42pub trait CanDeleteMessage {
43    fn delete(&self) -> DeleteMessage;
44}
45
46impl<M> CanDeleteMessage for M
47where
48    M: ToMessageId + ToSourceChat,
49{
50    fn delete(&self) -> DeleteMessage {
51        DeleteMessage::new(self.to_source_chat(), self.to_message_id())
52    }
53}