telegram_notifyrs/lib.rs
1use serde_json::json;
2use serde_json::{Map, Value};
3use ureq;
4
5/// Sends a Telegram message
6///
7/// Sends the supplied message to the designated chad ID, using the supplied token.
8pub fn send_message(msg: String, token: &str, chat_id: i64) -> ureq::Response {
9 let mut request_body = Map::new();
10 request_body.insert("text".to_string(), Value::String(msg));
11 request_body.insert("chat_id".to_string(), json!(chat_id));
12
13 let resp = ureq::post(&format!(
14 "https://api.telegram.org/bot{token}/sendMessage",
15 token = &token
16 ))
17 .send_json(json!(request_body));
18 return resp;
19}