sfr_core/
lib.rs

1#![warn(missing_docs)]
2#![warn(clippy::missing_docs_in_private_items)]
3#![doc = include_str!("./../README.md")]
4
5use sfr_types as st;
6
7mod app_credentials;
8mod config;
9mod inner;
10mod validation;
11
12pub use crate::app_credentials::AppCredentials;
13pub use crate::config::Config;
14pub use st::SlashCommandBody;
15pub use st::TextObject;
16pub use st::{Block, SectionBlock};
17pub use st::{OauthRedirectQuery, OauthV2AccessResponse};
18
19use validation::Validator;
20
21/// The type that handles a commonly used process of Slack App.
22#[derive(Clone)]
23pub struct Slack(inner::Inner);
24
25impl Slack {
26    /// The constructor.
27    pub fn new(creds: AppCredentials, config: Config) -> Self {
28        Self(inner::Inner::new(creds, config))
29    }
30
31    /// Returns the Slack Client App ID.
32    pub fn client_id(&self) -> &str {
33        self.0.client_id()
34    }
35
36    /// Returns the Slack Client App secret.
37    pub fn client_secret(&self) -> &str {
38        self.0.client_secret()
39    }
40
41    /// Returns [`Ok(())`][`Ok`] if `token` from args matches the Slack App's Verification Token.
42    pub fn verification_token(&self, body: &SlashCommandBody) -> Result<(), st::Error> {
43        self.0.verification_token(&body.token)
44    }
45
46    /// Validates the request from Slack.
47    ///
48    /// <https://api.slack.com/authentication/verifying-requests-from-slack>
49    pub fn validate_request(
50        &self,
51        signature: &str,
52        timestamp: &str,
53        body: &[u8],
54    ) -> Result<(), st::Error> {
55        self.0.validate_request(signature, timestamp, body)
56    }
57}