omnihook 0.1.2

Webhook client with payload builders for Slack, Discord, Telegram and generic webhooks with optional HMAC signing and idempotency key support.
Documentation
use serde_json::json;

use super::WebhookPayloadBuilder;

/// A payload builder for Slack notifications.
///
/// Creates a `blocks`-based section with mrkdwn-formatted text.
///
/// ### JSON Output
/// ```json
/// {
///   "blocks": [
///     {
///       "type": "section",
///       "text": {
///         "type": "mrkdwn",
///         "text": "Title\n\nBody message"
///       }
///     }
///   ]
/// }
/// ```
#[derive(Default)]
pub struct SlackPayloadBuilder;

impl WebhookPayloadBuilder for SlackPayloadBuilder {
    fn build_payload(&self, title: &str, body: &str) -> serde_json::Value {
        let full_message = format!("{title}\n\n{body}");
        json!({
            "blocks": [
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": full_message
                    }
                }
            ]
        })
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_slack_payload_builder() {
        let payload = SlackPayloadBuilder.build_payload("Test Title", "Test Message");
        assert_eq!(
            payload,
            json!({
                "blocks": [
                    {
                        "type": "section",
                        "text": {
                            "type": "mrkdwn",
                            "text": "Test Title\n\nTest Message"
                        }
                    }
                ]
            })
        );
    }
}