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