Slack Messaging

Version License Test

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

```rust use slackmessaging::Message; use slackmessaging::blocks::{elements::Button, Actions, Section};

[tokio::main]

async fn main() { let message = Message::new() .pushblock( Section::new() .settextmrkdwn("You have a new request:\n**") ) .pushblock( Section::new() .pushfieldmrkdwn("Type:\nComputer (laptop)") .pushfieldmrkdwn("When:\nSubmitted Aut 10") ) .pushblock( Actions::new() .pushelement( Button::new() .text("Approve") .setvalue("approve") .setprimary() ) .pushelement( Button::new() .text("Deny") .setvalue("deny") .set_danger() ) );

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

} ```

The message payload of the above example is following.

json { "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 Aut 10" } ] }, { "type": "actions", "elements": [ { "type": "button", "text": { "type": "plain_text", "text": "Approve", "emoji": true }, "value": "approve", "style": "primary" }, { "type": "button", "text": { "type": "plain_text", "text": "Deny", "emoji": true }, "value": "deny", "style": "danger" } ] } ] }

Optional Features

The following are a list of Cargo features that can be enabled or disabled.

fmt

Enable fmt module and format messages in this way.

```rust use chrono::prelude::*; use slack_messaging::fmt::DateFormat;

let dt = DateTime::parsefromrfc3339("2023-02-27T12:34:56+09:00").unwrap(); let f = DateFormat::new(dt).token("{date_short} at {time}");

asserteq!( format!("{f}"), "short} at {time}|Feb 27, 2023 at 12:34 PM>" ); ```

License

This software is released under the MIT License.