good-notifier 0.1.102

A good notifier for telegram and slack, and creating json logs
Documentation
#[derive(Debug, Clone)]
pub struct TelegramNotifier {
    pub token: String,
    pub chat_id: String,
}

impl TelegramNotifier {
    pub fn new(token: String, chat_id: String) -> Self {
        Self { token, chat_id }
    }

    pub async fn send_message(&self, message: &str) -> Result<(), anyhow::Error> {
        let encoded_message =
            url::form_urlencoded::byte_serialize(message.as_bytes()).collect::<String>();

        let url = format!(
            "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}",
            self.token, self.chat_id, encoded_message
        );

        let response = reqwest::get(&url).await?;

        if response.status().is_success() {
            Ok(())
        } else {
            let res = response.text().await?;
            Err(anyhow::anyhow!("failed to send message: {}", res))
        }
    }
}