Add donation notifications

This commit is contained in:
2023-05-24 21:30:21 +02:00
parent f9723361a0
commit 10b063ac25
6 changed files with 86 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
use moka::future::Cache;
use serde::Deserialize;
use serde_json::json;
use teloxide::types::UserId;
use teloxide::{types::{UserId, ChatId}};
use crate::config;
@@ -113,3 +113,25 @@ pub async fn update_user_activity(
Ok(())
}
pub async fn is_need_donate_notifications(chat_id: ChatId) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
let response = reqwest::Client::new()
.get(format!("{}/donate_notifications/{chat_id}/is_need_send", &config::CONFIG.user_settings_url))
.header("Authorization", &config::CONFIG.user_settings_api_key)
.send()
.await?
.error_for_status()?;
Ok(response.json::<bool>().await?)
}
pub async fn mark_donate_notification_sended(chat_id: ChatId) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
reqwest::Client::new()
.post(format!("{}/donate_notifications/{chat_id}", &config::CONFIG.user_settings_url))
.header("Authorization", &config::CONFIG.user_settings_api_key)
.send()
.await?
.error_for_status()?;
Ok(())
}