/*
* Copyright (C) 2025 Jonni Liljamo <jonni@liljamo.com>
*
* This file is licensed under GPL-3.0-or-later, see NOTICE and LICENSE for
* more information.
*/
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use crate::config::ServiceConfig;
use super::Service;
#[derive(Clone, Deserialize, Serialize)]
pub struct GotifyConfig {
pub instance: String,
pub token: String,
}
#[typetag::serde(name = "gotify")]
impl ServiceConfig for GotifyConfig {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
pub struct GotifyService {
client: reqwest::Client,
config: GotifyConfig,
}
impl GotifyService {
pub fn new(client: reqwest::Client, config: GotifyConfig) -> Self {
Self { client, config }
}
}
#[async_trait]
impl Service for GotifyService {
async fn send(&self, title: &str, message: &str) -> Result<(), Box<dyn std::error::Error>> {
let _ = self
.client
.post(format!("{}/message", self.config.instance))
.query(&[("token", &self.config.token)])
.form(&[("title", title), ("message", message)])
.send()
.await?;
Ok(())
}
}