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 crate::{methods, ImageMessage, TextMessage};
use serde_json::Value;

pub struct Configurations {
    token: String,
    custom_url: Option<String>,
}
impl Configurations {
    pub fn new(token: String, custom_url: Option<String>) -> Configurations {
        Configurations { token, custom_url }
    }
}

pub struct Client {
    // Each bot is given a unique authentication token when it is created. The token looks something like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11. You can learn about obtaining tokens and generating new ones in this document.
    base_url: String,
}
impl Client {
    pub fn new(configurations: Configurations) -> Client {
        let base_url = match configurations.custom_url {
            Some(custom_url) => format!("{}/bot{}", custom_url, configurations.token),
            None => format!("https://api.telegram.org/bot{}", configurations.token),
        };
        Client { base_url }
    }
    pub fn send_text(&self, message: TextMessage) -> Result<(), &'static str> {
        methods::text::send(message, &self.base_url)
    }
    pub fn send_image(&self, message: ImageMessage) -> Result<(), &'static str> {
        methods::image::send(message, &self.base_url)
    }
    pub fn get_update(&self) -> Result<Value, &'static str> {
        methods::updates::get(&self.base_url)
    }
}