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//! ## Events API and OAuth support for Hyper and Axum
61//!
62//! The library provides two different ways to work with Slack Events API:
63//! - Using pure Hyper-based solution
64//! - Using more high-level solution for axum web framework.
65//!
66//! Also the library provides Slack events signature verifier (`SlackEventSignatureVerifier`)
67//! (which is already integrated in the routes implementation for you).
68//! All you need is provide your client id and secret configuration to route implementation.
69//!
70//! ## Socket Mode support
71//!
72//! The library provides Socket Mode support additionally Events API leveraging Web-sockets
73//! in cases you don't want/need to expose publicly available HTTP endpoint.
74//!
75//! # Docs and examples
76//!
77//! Please follow to the official [website](https://slack-rust.abdolence.dev).
78//! Examples available on: [github](https://github.com/abdolence/slack-morphism-rust/tree/master/examples).
79//!
80
81#![allow(
82    clippy::new_without_default,
83    clippy::needless_lifetimes,
84    unused_imports
85)]
86
87pub use client::*;
88pub use scroller::*;
89pub use socket_mode::*;
90pub use token::*;
91
92mod models;
93pub use models::*;
94
95pub mod api;
96mod client;
97pub mod errors;
98pub mod listener;
99mod ratectl;
100mod scroller;
101#[cfg(feature = "signature-verifier")]
102pub mod signature_verifier;
103pub mod socket_mode;
104
105pub mod multipart_form;
106mod token;
107
108#[cfg(feature = "hyper")]
109pub mod hyper_tokio;
110
111#[cfg(feature = "axum")]
112pub mod axum_support;
113
114pub mod prelude;