telegram_bots_api/api/enums/
file_input.rs

1use crate::api::structs::input_file::InputFile;
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5/// File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ยป
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7#[serde(untagged)]
8pub enum FileInput {
9    InputFile(InputFile),
10    String(String),
11}
12
13impl Default for FileInput {
14    fn default() -> Self {
15        Self::String(String::from(""))
16    }
17}
18
19impl From<PathBuf> for FileInput {
20    fn from(path: PathBuf) -> Self {
21        let input_file = InputFile { path };
22
23        Self::InputFile(input_file)
24    }
25}
26
27impl From<InputFile> for FileInput {
28    fn from(file: InputFile) -> Self {
29        Self::InputFile(file)
30    }
31}
32
33impl From<String> for FileInput {
34    fn from(file: String) -> Self {
35        Self::String(file)
36    }
37}