rutebot/requests/
send_video.rs

1use 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/// Use this struct to send video files, Telegram clients support mp4 videos (other formats may be sent by `SendDocument`).
17/// On success, the sent `Message` is returned. Bots can currently
18/// send video files of up to 50 MB in size, this limit may be changed in the future
19#[derive(Serialize, Debug, Clone)]
20pub struct SendVideo<'a> {
21    /// Identifier for the target chat
22    pub chat_id: ChatId<'a>,
23
24    /// Video to send.
25    #[serde(skip_serializing_if = "FileKind::is_input_file")]
26    pub video: FileKind<'a>,
27
28    /// Video caption (may also be used when resending videos by file_id), 0-1024 characters
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub caption: Option<&'a str>,
31
32    /// Duration of sent video in seconds
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub duration: Option<i64>,
35
36    /// Video width
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub width: Option<i64>,
39
40    /// Video height
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub height: Option<i64>,
43
44    /// Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages).
45    /// Users will receive a notification with no sound.
46    #[serde(skip_serializing_if = "Not::not")]
47    pub disable_notification: bool,
48
49    /// Pass True, if the uploaded video is suitable for streaming.
50    #[serde(skip_serializing_if = "Not::not")]
51    pub supports_streaming: bool,
52
53    /// Send `ParseMode::Markdown` or `ParseMode::Html`,
54    /// if you want Telegram apps to show
55    /// [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in the media caption.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub parse_mode: Option<ParseMode>,
58
59    /// If the message is a reply, ID of the original message
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub reply_to_message_id: Option<i64>,
62
63    /// Additional interface options.
64    #[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}