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
use reqwest::blocking::{multipart, Client};
pub struct ImageMessage<'a> {
pub image_path: &'a str,
pub to: &'a str,
}
pub fn send(message: ImageMessage, base_url: &String) -> Result<(), &'static str> {
let reqwest = Client::new();
let body = multipart::Form::new()
.text("chat_id", String::from(message.to))
.file("photo", message.image_path);
let body = match body {
Ok(body) => body,
Err(_) => return Err("Failed to load the image"),
};
let result = reqwest
.post(format!("{}/sendPhoto", base_url))
.multipart(body)
.send();
match result {
Ok(_) => (),
Err(_) => return Err("Failed to send the request to telegram."),
};
Ok(())
}