Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 50 additions & 15 deletions backend/src/services/notification_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,56 @@ impl<'a> NotificationService<'a> {
message: format!("HTTP client setup failed: {err}"),
})?;

let response = client
.post(url)
.json(&json!({
"event": "Ping",
"timestamp": Utc::now().to_rfc3339()
}))
.send()
.await
.map_err(|err| ServiceError::ExternalService {
message: match err {
err if err.is_timeout() => "Webhook timeout after 5 seconds".into(),
err if err.is_connect() => "Could not connect to webhook server".into(),
_ => format!("Webhook communication failed: {err}"),
},
})?;
let response = if url.starts_with("https://hooks.slack.com/services/") {
client
.post(url)
.json(&json!({
"text": "Ping",
"blocks":[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Ping"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": format!("Timestamp: {}", Utc::now().to_rfc3339())
}
]
}
]
}))
.send()
.await
.map_err(|err| ServiceError::ExternalService {
message: match err {
err if err.is_timeout() => "Webhook timeout after 5 seconds".into(),
err if err.is_connect() => "Could not connect to webhook server".into(),
_ => format!("Webhook communication failed: {err}"),
},
})?
} else {
client
.post(url)
.json(&json!({
"event": "Ping",
"timestamp": Utc::now().to_rfc3339()
}))
.send()
.await
.map_err(|err| ServiceError::ExternalService {
message: match err {
err if err.is_timeout() => "Webhook timeout after 5 seconds".into(),
err if err.is_connect() => "Could not connect to webhook server".into(),
_ => format!("Webhook communication failed: {err}"),
},
})?
};

if !response.status().is_success() {
return Err(ServiceError::ExternalService {
Expand Down