Skip to content

Commit

Permalink
Merge pull request #8 from kaicoh/feature/builder
Browse files Browse the repository at this point in the history
Builder pattern
  • Loading branch information
kaicoh authored Apr 8, 2024
2 parents 7becfbe + 05da032 commit b9368db
Show file tree
Hide file tree
Showing 138 changed files with 20,393 additions and 11,277 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ all-features = true
chrono = { version = "0.4", optional = true }
regex = { version = "1.7", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

[dev-dependencies]
reqwest = { version = "0.11", features = ["json"] }
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }

[features]
Expand Down
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,42 @@ This is a library for [Rust](https://www.rust-lang.org/) to support building mes
Using this, you can build any messages in type-safe way like following.

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

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

let req = reqwest::Client::new()
.post("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX")
Expand Down Expand Up @@ -70,7 +76,7 @@ The message payload of the above example is following.
},
{
"type": "mrkdwn",
"text": "*When:*\nSubmitted Aut 10"
"text": "*When:*\nSubmitted Aug 10"
}
]
},
Expand All @@ -81,8 +87,7 @@ The message payload of the above example is following.
"type": "button",
"text": {
"type": "plain_text",
"text": "Approve",
"emoji": true
"text": "Approve"
},
"value": "approve",
"style": "primary"
Expand All @@ -91,8 +96,7 @@ The message payload of the above example is following.
"type": "button",
"text": {
"type": "plain_text",
"text": "Deny",
"emoji": true
"text": "Deny"
},
"value": "deny",
"style": "danger"
Expand Down
250 changes: 0 additions & 250 deletions src/attachment.rs

This file was deleted.

Loading

0 comments on commit b9368db

Please sign in to comment.