use reqwest::blocking::Client;
use serde_json::Value;
pub fn get(base_url: &String, offset: Option<u64>) -> Result<Value, &'static str> {
let reqwest = Client::new();
let offset = match offset {
Some(offset) => {
format!("?offset={}", offset)
}
None => String::from(""),
};
let response = match reqwest
.get(format!("{}/getUpdates{}", base_url, offset))
.send()
{
Ok(result) => {
if result.status() == 401 {
return Err("Invalid token");
}
let value: Value = result.json().unwrap();
if value["description"].to_string().contains("chat not found") {
return Err("No chat found with the given ID");
}
value
}
Err(_) => return Err("Failed to send the request to telegram."),
};
Ok(response)
}