Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder pattern #8

Merged
merged 7 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading