# `slack-framework-rs` `slack-framework-rs` is the library that [the author](https://gitlab.com/nogiro) uses to create the Slack App. Since it is for its own use, it currently provides only limited features, but it is strictly omitted from app-specific processing, so I think others can use it as well. However, there are some processes that have not been tested very well, so there may be things that do not work or do not represent. Issues and Merge Requests on GitLab are welcome. ## Features - [OAuth](https://api.slack.com/authentication/oauth-v2). - [Slash Commands](https://api.slack.com/interactivity/slash-commands) processing. (That includes [Verifying requests from Slack](https://api.slack.com/authentication/verifying-requests-from-slack), but not yet supported except in the case of Slash Commands.) - A client that can request a few [Slack APIs](https://api.slack.com/apis). - Some representations of [Blocks](https://api.slack.com/reference/block-kit/blocks). ### TODO (what I know) - OAuth [token rotation](https://api.slack.com/authentication/rotation). - More [APIs](https://api.slack.com/apis). - More representations of [Blocks](https://api.slack.com/reference/block-kit/blocks). ## Example ```rs use slack_framework_rs::core as sc; use slack_framework_rs::server as ss; use slack_framework_rs::slack_api as ssa; use slack_framework_rs::types as st; /// The structure for implementing handler traits. struct Handler; #[tokio::main] async fn main() -> Result<(), st::Error> { // Server settings let server_config = ss::Config::builder() .sock("127.0.0.1:3000".parse().unwrap()) .build(); // Slack App settings let slack_creds = sc::AppCredentials { id: "Client ID".into(), secret: "Client Secret".into(), signing_secret: "Signing Secret".into(), verification_token: "Verification Token".into(), }; let slack_config = sc::Config { timestamp_range: 300, }; let slack = Slack::new(slack_creds, slack_config); // HTTP Client let client = reqwest::Client::new(); // Starts serving Server::new( server_config, slack, client, Handler, Handler, Handler, ) .serve() .await } ``` ### Implementations of handlers ```rs /// Implements a process of slash commands. impl ss::SlashCommandHandlerTrait for Handler { async fn handle_slash_command( &self, _client: &Client, body: SlashCommandBody, ) -> Result { println!("body: {body:?}"); Ok(st::SlashCommandResponse::empty().into()) } } /// Implements a process of OAuth. impl ss::OauthHandlerTrait for Handler { async fn handle_oauth( &self, _client: reqwest::Client, body: OauthV2AccessResponse, ) -> Result, ResponseError> { println!("body: {body:?}"); Ok(None) } async fn take_oauth_token_from_team_id(&self, _team_id: &str) -> Result { Ok("token".into()) } fn redirect_uri(&self) -> &str { Ok("redirect_uri".into()) } } /// Implements to return the home page. /// The home page should have an `Add to Slack` button. impl HomeHandlerTrait for Handler { async fn handle_home(&self) -> Result, ResponseError> { const RESPONSE: &str = r#"ok"#; Ok(RESPONSE.into()) } } ``` ## Documents - [How to publish](https://gitlab.com/nogiro/slack-framework-rs/-/blob/master/docs/release/how-to-publish-to-crate-io.md)