telegram_bot_raw/requests/
send_video.rs1use std::borrow::Cow;
2
3use crate::requests::*;
4use crate::types::*;
5
6#[derive(Debug, Clone, PartialEq, PartialOrd)]
8#[must_use = "requests do nothing unless sent"]
9pub struct SendVideo<'c> {
10 chat_id: ChatRef,
11 video: InputFile,
12 caption: Option<Cow<'c, str>>,
13 parse_mode: Option<ParseMode>,
14 duration: Option<Integer>,
15 width: Option<Integer>,
16 height: Option<Integer>,
17 supports_streaming: bool,
18 thumb: Option<InputFile>,
19 reply_to_message_id: Option<MessageId>,
20 disable_notification: bool,
21 reply_markup: Option<ReplyMarkup>,
22}
23
24impl<'c> ToMultipart for SendVideo<'c> {
25 fn to_multipart(&self) -> Result<Multipart, Error> {
26 multipart_map! {
27 self,
28 (chat_id (text));
29 (video (raw));
30 (caption (text), optional);
31 (parse_mode (text), optional);
32 (duration (text), optional);
33 (width (text), optional);
34 (height (text), optional);
35 (supports_streaming (text), when_true);
36 (thumb (raw), optional);
37 (reply_to_message_id (text), optional);
38 (disable_notification (text), when_true);
39 (reply_markup (json), optional);
40 }
41 }
42}
43
44impl<'c> Request for SendVideo<'c> {
45 type Type = MultipartRequestType<Self>;
46 type Response = JsonIdResponse<Message>;
47
48 fn serialize(&self) -> Result<HttpRequest, Error> {
49 Self::Type::serialize(RequestUrl::method("sendVideo"), self)
50 }
51}
52
53impl<'c> SendVideo<'c> {
54 pub fn new<C, V>(chat: C, video: V) -> Self
55 where
56 C: ToChatRef,
57 V: Into<InputFile>,
58 {
59 Self {
60 chat_id: chat.to_chat_ref(),
61 video: video.into(),
62 caption: None,
63 parse_mode: None,
64 duration: None,
65 width: None,
66 height: None,
67 supports_streaming: false,
68 thumb: None,
69 reply_to_message_id: None,
70 reply_markup: None,
71 disable_notification: false,
72 }
73 }
74
75 pub fn thumb<V>(&mut self, thumb: V) -> &mut Self
76 where
77 V: Into<InputFileUpload>,
78 {
79 self.thumb = Some(thumb.into().into());
80 self
81 }
82
83 pub fn caption<T>(&mut self, caption: T) -> &mut Self
84 where
85 T: Into<Cow<'c, str>>,
86 {
87 self.caption = Some(caption.into());
88 self
89 }
90
91 pub fn parse_mode(&mut self, parse_mode: ParseMode) -> &mut Self {
92 self.parse_mode = Some(parse_mode);
93 self
94 }
95
96 pub fn duration(&mut self, duration: Integer) -> &mut Self {
97 self.duration = Some(duration);
98 self
99 }
100
101 pub fn width(&mut self, width: Integer) -> &mut Self {
102 self.width = Some(width);
103 self
104 }
105
106 pub fn height(&mut self, height: Integer) -> &mut Self {
107 self.height = Some(height);
108 self
109 }
110
111 pub fn supports_streaming(&mut self) -> &mut Self {
112 self.supports_streaming = true;
113 self
114 }
115
116 pub fn reply_to<R>(&mut self, to: R) -> &mut Self
117 where
118 R: ToMessageId,
119 {
120 self.reply_to_message_id = Some(to.to_message_id());
121 self
122 }
123
124 pub fn reply_markup<R>(&mut self, reply_markup: R) -> &mut Self
125 where
126 R: Into<ReplyMarkup>,
127 {
128 self.reply_markup = Some(reply_markup.into());
129 self
130 }
131
132 pub fn disable_notification(&mut self) -> &mut Self {
133 self.disable_notification = true;
134 self
135 }
136}
137
138pub trait CanReplySendVideo {
140 fn video_reply<'c, T>(&self, video: T) -> SendVideo<'c>
141 where
142 T: Into<InputFile>;
143}
144
145impl<M> CanReplySendVideo for M
146where
147 M: ToMessageId + ToSourceChat,
148{
149 fn video_reply<'c, T>(&self, video: T) -> SendVideo<'c>
150 where
151 T: Into<InputFile>,
152 {
153 let mut req = SendVideo::new(self.to_source_chat(), video);
154 req.reply_to(self);
155 req
156 }
157}
158
159pub trait CanSendVideo {
161 fn video<'c, T>(&self, video: T) -> SendVideo<'c>
162 where
163 T: Into<InputFile>;
164}
165
166impl<M> CanSendVideo for M
167where
168 M: ToChatRef,
169{
170 fn video<'c, T>(&self, video: T) -> SendVideo<'c>
171 where
172 T: Into<InputFile>,
173 {
174 SendVideo::new(self.to_chat_ref(), video)
175 }
176}