1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
//! # Slack Messaging
//!
//! This is a library to support building messages for [slack messaging api](https://api.slack.com/messaging/managing).
//! Using this, you can build any messages in type-safe way like following.
//!
//! ```
//! use slack_messaging::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>*")
//! )
//! .push_block(
//! Section::new()
//! .push_field_mrkdwn("*Type:*\nComputer (laptop)")
//! .push_field_mrkdwn("*When:*\nSubmitted Aut 10")
//! )
//! .push_block(
//! Actions::new()
//! .push_element(
//! Button::new()
//! .text("Approve")
//! .set_value("approve")
//! .set_primary()
//! )
//! .push_element(
//! Button::new()
//! .text("Deny")
//! .set_value("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](https://doc.rust-lang.org/stable/cargo/reference/features.html#the-features-section) that can be enabled or disabled:
//!
//! - **fmt** : Enable [fmt] module.
mod attachment;
/// Objects from that the [Message] and the [Attachment] are composed.
pub mod blocks;
/// Format text for slack app. Require `fmt` feature.
#[cfg(feature = "fmt")]
pub mod fmt;
mod message;
pub use attachment::Attachment;
pub use message::{Message, ResponseType};