telegram_bot_async_raw/requests/
delete_message.rs

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