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" } ] } ] }

License

This software is released under the MIT License.