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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
use serde::{Deserialize, Serialize};
/// One size of a photo or file thumbnail.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PhotoSize {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// Photo width in pixels.
pub width: u32,
/// Photo height in pixels.
pub height: u32,
/// File size in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<u64>,
}
/// This object represents a file ready to be downloaded.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct File {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// File size in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<u64>,
/// Relative file path — use with
/// `https://api.telegram.org/file/bot<TOKEN>/<file_path>`.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_path: Option<String>,
}
impl File {
/// Constructs the full download URL for this file.
#[must_use]
pub fn url(&self, token: &str) -> Option<String> {
self.file_path
.as_ref()
.map(|path| format!("https://api.telegram.org/file/bot{token}/{path}"))
}
}
/// Audio file to be treated as music.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Audio {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// Duration of the audio in seconds.
pub duration: u32,
/// Performer of the audio as defined by the sender or audio tags.
#[serde(skip_serializing_if = "Option::is_none")]
pub performer: Option<String>,
/// Title of the audio as defined by the sender or audio tags.
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
/// Original filename as defined by the sender.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
/// MIME type of the audio.
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
/// File size in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<u64>,
/// Thumbnail of the album cover.
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail: Option<PhotoSize>,
}
/// General file (not photo, voice, audio or video).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Document {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// Document thumbnail.
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail: Option<PhotoSize>,
/// Original filename as defined by the sender.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
/// MIME type of the document.
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
/// File size in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<u64>,
}
/// Video file.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Video {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// Video width in pixels.
pub width: u32,
/// Video height in pixels.
pub height: u32,
/// Duration of the video in seconds.
pub duration: u32,
/// Video thumbnail.
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail: Option<PhotoSize>,
/// Cover image for the video.
#[serde(skip_serializing_if = "Option::is_none")]
pub cover: Option<Vec<PhotoSize>>,
/// Start timestamp for video chapters.
#[serde(skip_serializing_if = "Option::is_none")]
pub start_timestamp: Option<u32>,
/// Original filename.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
/// MIME type of the video.
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
/// File size in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<u64>,
}
/// Animation file (GIF or H.264/MPEG-4 AVC, no sound).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Animation {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// Animation width in pixels.
pub width: u32,
/// Animation height in pixels.
pub height: u32,
/// Duration of the animation in seconds.
pub duration: u32,
/// Animation thumbnail.
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail: Option<PhotoSize>,
/// Original filename as defined by the sender.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
/// MIME type of the animation.
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
/// File size in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<u64>,
}
/// Voice note (OGG/OPUS audio).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Voice {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// Duration of the voice note in seconds.
pub duration: u32,
/// MIME type of the voice note.
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
/// File size in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<u64>,
}
/// Rounded-square MPEG4 video note.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VideoNote {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// Video width and height (diameter of the circle).
pub length: u32,
/// Duration of the video in seconds.
pub duration: u32,
/// Video thumbnail.
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail: Option<PhotoSize>,
/// File size in bytes.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_size: Option<u64>,
}
/// Represents a file to be sent.
#[derive(Debug, Clone)]
pub enum InputFile {
/// Send an existing file by its Telegram `file_id`.
FileId(String),
/// Send a file from a URL (photo ≤5 MB, others ≤20 MB).
Url(String),
/// Upload new file bytes. The `filename` is sent in the Content-Disposition header.
Bytes {
/// Original filename sent in the Content-Disposition header.
filename: String,
/// Raw file bytes.
data: Vec<u8>,
/// MIME type of the file.
mime_type: String,
},
/// Reference an already-included multipart attachment by `attach://<name>`.
Attach(String),
}
impl InputFile {
/// Returns the string representation for JSON/query-string fields.
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::FileId(id) => id,
Self::Url(url) => url,
Self::Attach(name) => name,
Self::Bytes { filename, .. } => filename,
}
}
/// Returns `true` if this variant needs multipart form upload.
#[must_use]
pub fn requires_multipart(&self) -> bool {
matches!(self, Self::Bytes { .. })
}
}
/// Encrypted passport file.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PassportFile {
/// Telegram file identifier.
pub file_id: String,
/// Unique file identifier, stable across bots and time.
pub file_unique_id: String,
/// File size in bytes.
pub file_size: u64,
/// Unix timestamp when the file was uploaded.
pub file_date: i64,
}