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
use std::collections::HashMap;

use reqwest::blocking::Client;

pub struct TextMessage<'a> {
    pub content: &'a str,
    pub to: &'a str,
}

pub fn send(message: TextMessage, base_url: &String) -> Result<(), &'static str> {
    let reqwest = Client::new();

    let mut body = HashMap::new();
    body.insert("chat_id", &message.to);
    body.insert("text", &message.content);
    let result = reqwest
        .post(format!("{}/sendMessage", base_url))
        .json(&body)
        .send();
    match result {
        Ok(_) => (),
        Err(_) => return Err("Failed to send the request to telegram."),
    }

    Ok(())
}