slack-framework-rs

Crates.ioslack-framework-rs
lib.rsslack-framework-rs
version0.1.1
sourcesrc
created_at2024-09-04 14:35:25.064813
updated_at2024-10-01 00:53:28.780444
description`slack-framework-rs` is the library that [the author](https://gitlab.com/nogiro) uses to create the Slack App.
homepage
repositoryhttps://gitlab.com/nogiro/slack-framework-rs
max_upload_size
id1363395
size2,200,198
(nogiro)

documentation

README

slack-framework-rs

slack-framework-rs is the library that the author 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

TODO (what I know)

Example

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

/// Implements a process of slash commands.
impl ss::SlashCommandHandlerTrait for Handler {
    async fn handle_slash_command(
        &self,
        _client: &Client,
        body: SlashCommandBody,
    ) -> Result<st::SlashCommandResponse, ResponseError> {
        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<Option<OauthRedirectResponse>, ResponseError> {
        println!("body: {body:?}");
        Ok(None)
    }

    async fn take_oauth_token_from_team_id(&self, _team_id: &str) -> Result<String, ResponseError> {
        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<Vec<u8>, ResponseError> {
        const RESPONSE: &str = r#"<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body>ok</body></html>"#;
        Ok(RESPONSE.into())
    }
}

Documents

Commit count: 117

cargo fmt