telegram_bot_raw/requests/
forward_message.rs

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