Crate slack_blocks[][src]

Expand description

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.

Every model has builders that leverage Rust’s type system to help you make sure what you’re sending to Slack is 100% valid to them.

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::mox::*;

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>
};

Modules

blocks

Layout Blocks

compose

Composition Objects

elems

Block Elements - interactive components

moxxml

XML macro support

text

Text Object

Enums

Block

Layout Blocks

BlockElement

Block Elements - interactive components