slack_morphism/lib.rs
1//! # Slack Morphism for Rust
2//!
3//! Slack Morphism is a modern client library for Slack Web/Events API and Block Kit.
4//!
5//! ## Slack Web API client
6//!
7//! ### Create a client instance:
8//! ```ignore
9//! use slack_morphism::prelude::*;
10//!
11//! let client = SlackClient::new(SlackClientHyperConnector::new());
12//!
13//! ```
14//!
15//! ### Make Web API methods calls
16//!
17//! For most of Slack Web API methods (except for OAuth methods, Incoming Webhooks and event replies)
18//! you need a Slack token to make a call.
19//! For simple bots you can have it in your config files, or you can obtain
20//! workspace tokens using Slack OAuth.
21//!
22//! In the example below, we’re using a hardcoded Slack token, but don’t do that for your production bots and apps.
23//! You should securely and properly store all of Slack tokens.
24//!
25//! ```ignore
26//!
27//! use slack_morphism::prelude::*;
28//!
29//!# async fn example() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
30//!
31//! let client = SlackClient::new(SlackClientHyperConnector::new());
32//!
33//! // Create our Slack API token
34//! let token_value: SlackApiTokenValue = "xoxb-89.....".into();
35//! let token: SlackApiToken = SlackApiToken::new(token_value);
36//!
37//! // Create a Slack session with this token
38//! // A session is just a lightweight wrapper around your token
39//! // not to specify it all the time for series of calls.
40//! let session = client.open_session(&token);
41//!
42//! // Make your first API call (which is `api.test` here)
43//! let test: SlackApiTestResponse = session
44//! .api_test(&SlackApiTestRequest::new().with_foo("Test".into()))
45//! .await?;
46//!
47//! // Send a simple text message
48//! let post_chat_req =
49//! SlackApiChatPostMessageRequest::new("#general".into(),
50//! SlackMessageContent::new().with_text("Hey there!".into())
51//! );
52//!
53//! let post_chat_resp = session.chat_post_message(&post_chat_req).await?;
54//!
55//!# Ok(())
56//!# }
57//!
58//! ```
59//!
60//! ## Block Kit
61//!
62//! Blocks, block elements, and views are modeled as typed structs and enums,
63//! with the [`slack_blocks!`] macro (and [`md!`]/[`pt!`] for text objects)
64//! to build the block lists they hold:
65//!
66//! ```
67//! use slack_morphism::prelude::*;
68//!
69//! let show_footer = true;
70//!
71//! let blocks: Vec<SlackBlock> = slack_blocks![
72//! SlackHeaderBlock::new(pt!("Deploy report")),
73//! SlackSectionBlock::new()
74//! .with_text(md!("Deployed *{}* to {}", "api", "us-east-1"))
75//! .with_fields(vec![md!("*Duration:*\n42s"), md!("*Result:*\nsuccess")]),
76//! SlackActionsBlock::new(slack_blocks![
77//! SlackBlockButtonElement::new(pt!("Rollback"))
78//! .with_action_id("rollback".into())
79//! .with_style(SlackBlockButtonStyle::Danger),
80//! SlackBlockButtonElement::new(pt!("View details")).with_action_id("details".into()),
81//! ]),
82//! SlackRichTextBlock::new(vec![SlackRichTextSection::new(vec![
83//! "Triggered by ".into(),
84//! SlackRichTextText::new("the release bot".to_string()).bold().into(),
85//! ])
86//! .into()]),
87//! SlackTableBlock::new(vec![
88//! vec!["Service".into(), "Status".into()],
89//! vec!["api".into(), "healthy".into()],
90//! ]),
91//! optionally(show_footer => SlackContextBlock::new(vec![md!("Posted automatically")])),
92//! ];
93//!
94//! let content = SlackMessageContent::new().with_blocks(blocks);
95//! # assert!(content.blocks.is_some());
96//! ```
97//!
98//! See the [`blocks::block_kit`] module docs for a full guide covering text
99//! objects, sections, actions and inputs, rich text, tables, templates, and
100//! views.
101//!
102//! ## Events API and OAuth support for Hyper and Axum
103//!
104//! The library provides two different ways to work with Slack Events API:
105//! - Using pure Hyper-based solution
106//! - Using more high-level solution for axum web framework.
107//!
108//! Also the library provides Slack events signature verifier (`SlackEventSignatureVerifier`)
109//! (which is already integrated in the routes implementation for you).
110//! All you need is provide your client id and secret configuration to route implementation.
111//!
112//! ## Socket Mode support
113//!
114//! The library provides Socket Mode support additionally Events API leveraging Web-sockets
115//! in cases you don't want/need to expose publicly available HTTP endpoint.
116//!
117//! # Docs and examples
118//!
119//! Please follow to the official [website](https://slack-rust.abdolence.dev).
120//! Examples available on: [github](https://github.com/abdolence/slack-morphism-rust/tree/master/examples).
121//!
122
123#![allow(
124 clippy::new_without_default,
125 clippy::needless_lifetimes,
126 unused_imports
127)]
128
129pub use client::*;
130pub use scroller::*;
131pub use socket_mode::*;
132pub use token::*;
133
134mod models;
135pub use models::*;
136
137pub mod api;
138mod client;
139pub mod errors;
140pub mod listener;
141mod ratectl;
142mod scroller;
143#[cfg(feature = "signature-verifier")]
144pub mod signature_verifier;
145pub mod socket_mode;
146
147pub mod multipart_form;
148mod token;
149
150#[cfg(feature = "hyper-base")]
151pub mod hyper_tokio;
152
153#[cfg(feature = "axum-base")]
154pub mod axum_support;
155
156pub mod prelude;