#slack #models #messages #model

slack-blocks

Models + clientside validation for Slack's JSON Block Kit

82 releases (24 breaking)

0.25.0 Jun 5, 2021
0.23.1 Jun 2, 2021
0.9.12 Aug 6, 2020
0.9.11 Jul 26, 2020

#560 in Data structures

Download history 6/week @ 2024-07-19 19/week @ 2024-07-26 84/week @ 2024-08-02 7/week @ 2024-08-09 24/week @ 2024-08-16 14/week @ 2024-08-23 14/week @ 2024-08-30 24/week @ 2024-09-06 43/week @ 2024-09-13 28/week @ 2024-09-20 183/week @ 2024-09-27 116/week @ 2024-10-04 35/week @ 2024-10-11 8/week @ 2024-10-18 8/week @ 2024-10-25 81/week @ 2024-11-01

140 downloads per month

MIT/Apache

380KB
4.5K SLoC

crates.io docs.rs Maintenance

slack-blocks

This crate brings Slack's terrific Block Kit 🔗 to the Rust ecosystem.

Inside, you'll find models for all of Slack's Layout Blocks, Block Elements, and Composition Objects. Each structure has Slack's API documentation copied in-place so you don't have to leave your editor to remember the details of the block kit API.

Every model has builders that leverage Rust's type system to help you provide every required field, so you can be confident in your app.

Troubleshooting common compiler errors

Method build not found for ...Builder - Dig into the error message, you'll find something like RequiredMethodNotCalled<method::foo>, meaning you need to call .foo() before you can call .build()!

Example

Using an example from Slack's Documentation:

{
  "type": "section",
  "text": {
    "text": "*Sally* has requested you set the deadline for the Nano launch project",
    "type": "mrkdwn"
  },
  "accessory": {
    "type": "datepicker",
    "action_id": "datepicker123",
    "initial_date": "1990-04-28",
    "placeholder": {
      "type": "plain_text",
      "text": "Select a date"
    }
  }
}

You can use raw Builders like so:

use slack_blocks::{text::ToSlackMarkdown, blocks::Section, elems::DatePicker};

let section = Section::builder()
                      .text("*Sally* has requested you set the deadline for the Nano launch project".markdown())
                      .accessory(DatePicker::builder()
                                            .action_id("datepicker123")
                                            .initial_date((28, 4, 1990))
                                            .placeholder("Select a date")
                                            .build()
                      )
                      .build();

Or enable the unstable feature and use xml macros:

use slack_blocks::blox::*;

let pick_date = blox! {
  <date_picker action_id="datepicker123"
               placeholder="Select a date"
               initial_date=(28, 4, 1990) />
};

let section = blox! {
  <section_block accessory=pick_date>
    <text kind=plain>"*Sally* has requested you set the deadline for the Nano launch project"</text>
  </section_block>
};

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.3–2MB
~44K SLoC