chipa_webhooks/platform/
mod.rs1use serde_json::{Map, Value};
2
3use crate::error::WebhookError;
4
5pub mod discord;
6pub mod generic;
7pub mod ntfy;
8pub mod slack;
9pub mod telegram;
10
11pub trait Platform: Send + Sync {
12 fn build_payload(&self, rendered: &str, hints: &Map<String, Value>) -> Value;
13 fn endpoint(&self) -> &str;
14}
15
16pub async fn post(
17 client: &reqwest::Client,
18 platform: &dyn Platform,
19 rendered: &str,
20 hints: &Map<String, Value>,
21 destination_name: &str,
22) -> Result<(), WebhookError> {
23 let payload = platform.build_payload(rendered, hints);
24
25 let response = client
26 .post(platform.endpoint())
27 .json(&payload)
28 .send()
29 .await
30 .map_err(|e| WebhookError::Http {
31 destination: destination_name.to_owned(),
32 source: e,
33 })?;
34
35 if !response.status().is_success() {
36 let status = response.status();
37 tracing::warn!(destination = destination_name, status = %status, "webhook returned non-2xx");
38 }
39
40 Ok(())
41}