telegram_bot_async_raw/requests/
forward_message.rs

1use std::ops::Not;
2
3use crate::{requests::*, types::*};
4
5/// Use this method to forward messages of any kind.
6#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
7#[must_use = "requests do nothing unless sent"]
8pub struct ForwardMessage {
9    chat_id: ChatRef,
10    from_chat_id: ChatRef,
11    #[serde(skip_serializing_if = "Not::not")]
12    disable_notification: bool,
13    message_id: MessageId,
14}
15
16impl Request for ForwardMessage {
17    type Type = JsonRequestType<Self>;
18    type Response = JsonIdResponse<Message>;
19
20    fn serialize(&self) -> Result<HttpRequest, Error> {
21        Self::Type::serialize(RequestUrl::method("forwardMessage"), self)
22    }
23}
24
25impl ForwardMessage {
26    pub fn new<M, F, T>(message: M, from: F, to: T) -> Self
27    where
28        M: ToMessageId,
29        F: ToChatRef,
30        T: ToChatRef,
31    {
32        ForwardMessage {
33            chat_id: to.to_chat_ref(),
34            from_chat_id: from.to_chat_ref(),
35            disable_notification: false,
36            message_id: message.to_message_id(),
37        }
38    }
39
40    pub fn disable_notification(mut self) -> Self {
41        self.disable_notification = true;
42        self
43    }
44}
45
46/// Forward message.
47pub trait CanForwardMessage {
48    fn forward<T>(&self, to: T) -> ForwardMessage
49    where
50        T: ToChatRef;
51}
52
53impl<M> CanForwardMessage for M
54where
55    M: ToMessageId + ToSourceChat,
56{
57    fn forward<T>(&self, to: T) -> ForwardMessage
58    where
59        T: ToChatRef,
60    {
61        ForwardMessage::new(self.to_message_id(), self.to_source_chat(), to)
62    }
63}