diff --git a/src/channels/discord.rs b/src/channels/discord.rs index fd5fe37..b9e4da6 100644 --- a/src/channels/discord.rs +++ b/src/channels/discord.rs @@ -87,13 +87,23 @@ impl Channel for DiscordChannel { let url = format!("https://discord.com/api/v10/channels/{channel_id}/messages"); let body = json!({ "content": message }); - self.client + let resp = self + .client .post(&url) .header("Authorization", format!("Bot {}", self.bot_token)) .json(&body) .send() .await?; + if !resp.status().is_success() { + let status = resp.status(); + let err = resp + .text() + .await + .unwrap_or_else(|e| format!("")); + anyhow::bail!("Discord send message failed ({status}): {err}"); + } + Ok(()) } diff --git a/src/channels/slack.rs b/src/channels/slack.rs index d8b35cb..5a18cc3 100644 --- a/src/channels/slack.rs +++ b/src/channels/slack.rs @@ -58,13 +58,34 @@ impl Channel for SlackChannel { "text": message }); - self.client + let resp = self + .client .post("https://slack.com/api/chat.postMessage") .bearer_auth(&self.bot_token) .json(&body) .send() .await?; + let status = resp.status(); + let body = resp + .text() + .await + .unwrap_or_else(|e| format!("")); + + if !status.is_success() { + anyhow::bail!("Slack chat.postMessage failed ({status}): {body}"); + } + + // Slack returns 200 for most app-level errors; check JSON "ok" field + let parsed: serde_json::Value = serde_json::from_str(&body).unwrap_or_default(); + if parsed.get("ok") == Some(&serde_json::Value::Bool(false)) { + let err = parsed + .get("error") + .and_then(|e| e.as_str()) + .unwrap_or("unknown"); + anyhow::bail!("Slack chat.postMessage failed: {err}"); + } + Ok(()) } diff --git a/src/channels/telegram.rs b/src/channels/telegram.rs index 1f9b202..49ff843 100644 --- a/src/channels/telegram.rs +++ b/src/channels/telegram.rs @@ -376,12 +376,22 @@ impl Channel for TelegramChannel { "parse_mode": "Markdown" }); - self.client + let resp = self + .client .post(self.api_url("sendMessage")) .json(&body) .send() .await?; + if !resp.status().is_success() { + let status = resp.status(); + let err = resp + .text() + .await + .unwrap_or_else(|e| format!("")); + anyhow::bail!("Telegram sendMessage failed ({status}): {err}"); + } + Ok(()) } diff --git a/src/util.rs b/src/util.rs index 077ccad..9a218e7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,4 @@ -//! Utility functions for ZeroClaw. +//! Utility functions for `ZeroClaw`. //! //! This module contains reusable helper functions used across the codebase. @@ -58,7 +58,10 @@ mod tests { fn test_truncate_ascii_with_truncation() { // ASCII string longer than limit - truncates assert_eq!(truncate_with_ellipsis("hello world", 5), "hello..."); - assert_eq!(truncate_with_ellipsis("This is a long message", 10), "This is a..."); + assert_eq!( + truncate_with_ellipsis("This is a long message", 10), + "This is a..." + ); } #[test]