-
Notifications
You must be signed in to change notification settings - Fork 4
/
file.rs
35 lines (31 loc) · 1.13 KB
/
file.rs
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
use std::env;
use telbot_hyper::{
types::{file::InputFile, update::GetUpdates},
Api,
};
#[tokio::main]
async fn main() {
let api = Api::new(env::var("BOT_TOKEN").unwrap());
let mut offset = 0;
loop {
let get_updates = GetUpdates::new().with_offset(offset as i32).with_timeout(1);
let updates = api.send_json(&get_updates).await.unwrap();
for update in updates {
if let Some(message) = update.kind.message() {
if matches!(message.kind.text(), Some(text) if text.starts_with("/start")) {
let photo = InputFile {
name: "clover.jpg".to_string(),
data: include_bytes!("clover.jpg").to_vec(),
mime: "image/jpg".to_string(),
};
let request = message.chat.send_photo(photo);
let api = api.clone();
tokio::spawn(async move {
api.send_file(&request).await.unwrap();
});
}
}
offset = offset.max(update.update_id + 1);
}
}
}