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
#![warn(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]
#![doc = include_str!("./../README.md")]

use sfr_types as st;

mod app_credentials;
mod config;
mod inner;
mod validation;

pub use crate::app_credentials::AppCredentials;
pub use crate::config::Config;
pub use st::SlashCommandBody;
pub use st::TextObject;
pub use st::{Block, SectionBlock};
pub use st::{OauthRedirectQuery, OauthV2AccessResponse};

use validation::Validator;

/// The type that handles a commonly used process of Slack App.
#[derive(Clone)]
pub struct Slack(inner::Inner);

impl Slack {
    /// The constructor.
    pub fn new(creds: AppCredentials, config: Config) -> Self {
        Self(inner::Inner::new(creds, config))
    }

    /// Returns the Slack Client App ID.
    pub fn client_id(&self) -> &str {
        self.0.client_id()
    }

    /// Returns the Slack Client App secret.
    pub fn client_secret(&self) -> &str {
        self.0.client_secret()
    }

    /// Returns [`Ok(())`][`Ok`] if `token` from args matches the Slack App's Verification Token.
    pub fn verification_token(&self, body: &SlashCommandBody) -> Result<(), st::Error> {
        self.0.verification_token(&body.token)
    }

    /// Validates the request from Slack.
    ///
    /// <https://api.slack.com/authentication/verifying-requests-from-slack>
    pub fn validate_request(
        &self,
        signature: &str,
        timestamp: &str,
        body: &[u8],
    ) -> Result<(), st::Error> {
        self.0.validate_request(signature, timestamp, body)
    }
}