iqps_backend/
slack.rs

1//! Utils for Slack App integration.
2
3use color_eyre::eyre;
4use http::StatusCode;
5
6/// Sends a notification to the Slack channel.
7pub async fn send_slack_message(
8    webhook_url: &str,
9    message: &str,
10) -> Result<(), color_eyre::eyre::Error> {
11    if webhook_url.is_empty() {
12        return Ok(());
13    }
14
15    let client = reqwest::Client::new();
16    let response = client
17        .post(webhook_url)
18        .json(&serde_json::json!({ "text": message }))
19        .send()
20        .await?;
21
22    if response.status() != StatusCode::OK {
23        return Err(eyre::eyre!(
24            "Failed to send message to Slack: {}",
25            response.status()
26        ));
27    }
28
29    Ok(())
30}