#slack #webhook

slack-messaging

Support building Slack Block Kit message

18 unstable releases (6 breaking)

Uses new Rust 2024

0.7.3 Mar 16, 2026
0.7.2 Dec 18, 2025
0.6.0 Dec 12, 2025
0.5.3 Nov 26, 2025
0.2.2 Mar 2, 2023

#145 in Web programming

Download history 2589/week @ 2025-12-12 1052/week @ 2025-12-19 690/week @ 2025-12-26 2841/week @ 2026-01-02 2490/week @ 2026-01-09 1647/week @ 2026-01-16 2147/week @ 2026-01-23 2282/week @ 2026-01-30 2137/week @ 2026-02-06 1867/week @ 2026-02-13 2467/week @ 2026-02-20 1281/week @ 2026-02-27 2642/week @ 2026-03-06 2244/week @ 2026-03-13 2360/week @ 2026-03-20 2288/week @ 2026-03-27

9,695 downloads per month
Used in 2 crates

MIT license

485KB
9K SLoC

Slack Messaging

Version License Test

This is a library for Rust to support building Slack Block Kit messages. Using this, you can build any messages in type-safe way like following.

use slack_messaging::{mrkdwn, plain_text, Message};
use slack_messaging::blocks::{elements::Button, Actions, Section};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let message = Message::builder()
        .block(
            Section::builder()
                .text(mrkdwn!("You have a new request:\n*<fakeLink.toEmployeeProfile.com|Fred Enriquez - New device request>*")?)
                .build()?
        )
        .block(
            Section::builder()
                .field(mrkdwn!("*Type:*\nComputer (laptop)")?)
                .field(mrkdwn!("*When:*\nSubmitted Aug 10")?)
                .build()?
        )
        .block(
            Actions::builder()
                .element(
                    Button::builder()
                        .text(plain_text!("Approve")?)
                        .value("approve")
                        .primary()
                        .build()?
                )
                .element(
                    Button::builder()
                        .text(plain_text!("Deny")?)
                        .value("deny")
                        .danger()
                        .build()?
                )
                .build()?
        )
        .build()?;

    let req = reqwest::Client::new()
        .post("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX")
        .json(&message);

    if let Err(err) = req.send().await {
        eprintln!("{err}");
    }

    Ok(())
}

The message payload of the above example is following.

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "You have a new request:\n*<fakeLink.toEmployeeProfile.com|Fred Enriquez - New device request>*"
            }
        },
        {
            "type": "section",
            "fields": [
                {
                    "type": "mrkdwn",
                    "text": "*Type:*\nComputer (laptop)"
                },
                {
                    "type": "mrkdwn",
                    "text": "*When:*\nSubmitted Aug 10"
                }
            ]
        },
        {
            "type": "actions",
            "elements": [
                {
                    "type": "button",
                    "text": {
                        "type": "plain_text",
                        "text": "Approve"
                    },
                    "value": "approve",
                    "style": "primary"
                },
                {
                    "type": "button",
                    "text": {
                        "type": "plain_text",
                        "text": "Deny"
                    },
                    "value": "deny",
                    "style": "danger"
                }
            ]
        }
    ]
}

License

This software is released under the MIT License.

Dependencies

~3.5–6MB
~106K SLoC