conogram/entities/
input_media_document.rs

1use serde::Serialize;
2
3use crate::{
4    entities::{
5        message_entity::MessageEntity,
6        misc::input_file::{GetFiles, InputFile},
7    },
8    utils::deserialize_utils::is_false,
9};
10
11/// Represents a general file to be sent.
12///
13/// API Reference: [link](https://core.telegram.org/bots/api/#inputmediadocument)
14#[derive(Debug, Clone, Default, PartialEq, Serialize)]
15pub struct InputMediaDocument {
16    /// File to send. Pass a file\_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://\<file\_attach\_name\>” to upload a new one using multipart/form-data under \<file\_attach\_name\> name. [More information on Sending Files »](https://core.telegram.org/bots/api/#sending-files)
17    pub media: InputFile,
18
19    /// *Optional*. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://\<file\_attach\_name\>” if the thumbnail was uploaded using multipart/form-data under \<file\_attach\_name\>. [More information on Sending Files »](https://core.telegram.org/bots/api/#sending-files)
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub thumbnail: Option<InputFile>,
22
23    /// *Optional*. Caption of the document to be sent, 0-1024 characters after entities parsing
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub caption: Option<String>,
26
27    /// *Optional*. Mode for parsing entities in the document caption. See [formatting options](https://core.telegram.org/bots/api/#formatting-options) for more details.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub parse_mode: Option<String>,
30
31    /// *Optional*. List of special entities that appear in the caption, which can be specified instead of *parse\_mode*
32    #[serde(skip_serializing_if = "Vec::is_empty")]
33    pub caption_entities: Vec<MessageEntity>,
34
35    /// *Optional*. Disables automatic server-side content type detection for files uploaded using multipart/form-data. Always *True*, if the document is sent as part of an album.
36    #[serde(skip_serializing_if = "is_false")]
37    pub disable_content_type_detection: bool,
38}
39
40impl GetFiles for InputMediaDocument {
41    fn get_files(&self) -> Vec<&InputFile> {
42        let mut vec = Vec::with_capacity(2);
43        vec.push(&self.media);
44        if let Some(thumbnail) = &self.thumbnail {
45            vec.push(thumbnail);
46        }
47        vec
48    }
49}
50// Divider: all content below this line will be preserved after code regen
51impl<T: Into<InputFile>> From<T> for InputMediaDocument {
52    fn from(value: T) -> Self {
53        Self {
54            media: value.into(),
55            ..Default::default()
56        }
57    }
58}