rutebot/requests/
send_video.rs1use std::ops::Not;
2
3use hyper::Body;
4use hyper_multipart_rfc7578::client::multipart::Form;
5use serde::Serialize;
6
7use crate::{
8 error::Error,
9 requests::{
10 add_fields_to_form, add_file_to_form, add_form_body, add_json_body, ChatId, FileKind,
11 ParseMode, ReplyMarkup, Request,
12 },
13 responses::Message,
14};
15
16#[derive(Serialize, Debug, Clone)]
20pub struct SendVideo<'a> {
21 pub chat_id: ChatId<'a>,
23
24 #[serde(skip_serializing_if = "FileKind::is_input_file")]
26 pub video: FileKind<'a>,
27
28 #[serde(skip_serializing_if = "Option::is_none")]
30 pub caption: Option<&'a str>,
31
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub duration: Option<i64>,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
38 pub width: Option<i64>,
39
40 #[serde(skip_serializing_if = "Option::is_none")]
42 pub height: Option<i64>,
43
44 #[serde(skip_serializing_if = "Not::not")]
47 pub disable_notification: bool,
48
49 #[serde(skip_serializing_if = "Not::not")]
51 pub supports_streaming: bool,
52
53 #[serde(skip_serializing_if = "Option::is_none")]
57 pub parse_mode: Option<ParseMode>,
58
59 #[serde(skip_serializing_if = "Option::is_none")]
61 pub reply_to_message_id: Option<i64>,
62
63 #[serde(skip_serializing_if = "Option::is_none")]
65 pub reply_markup: Option<ReplyMarkup<'a>>,
66}
67
68impl<'a> Request for SendVideo<'a> {
69 type ResponseType = Message;
70
71 fn method(&self) -> &'static str {
72 "sendVideo"
73 }
74
75 fn set_http_request_body(
76 self,
77 request_builder: hyper::http::request::Builder,
78 ) -> Result<hyper::http::request::Request<Body>, Error> {
79 if self.video.is_input_file() {
80 let mut form = Form::default();
81 add_fields_to_form(&mut form, &self)?;
82 add_file_to_form(&mut form, self.video, Some("video"));
83 add_form_body(request_builder, form)
84 } else {
85 add_json_body(request_builder, &self)
86 }
87 }
88}
89
90impl<'a> SendVideo<'a> {
91 pub fn new(chat_id: impl Into<ChatId<'a>>, video: FileKind<'a>) -> Self {
92 Self {
93 chat_id: chat_id.into(),
94 video,
95 caption: None,
96 duration: None,
97 width: None,
98 disable_notification: false,
99 supports_streaming: false,
100 parse_mode: None,
101 reply_to_message_id: None,
102 reply_markup: None,
103 height: None,
104 }
105 }
106
107 pub fn new_reply(
108 chat_id: impl Into<ChatId<'a>>,
109 video: FileKind<'a>,
110 reply_to_message_id: i64,
111 ) -> Self {
112 Self {
113 chat_id: chat_id.into(),
114 video,
115 caption: None,
116 duration: None,
117 width: None,
118 disable_notification: false,
119 supports_streaming: false,
120 parse_mode: None,
121 reply_to_message_id: Some(reply_to_message_id),
122 reply_markup: None,
123 height: None,
124 }
125 }
126}