Skip to content

Latest commit

 

History

History
139 lines (100 loc) · 3.32 KB

File metadata and controls

139 lines (100 loc) · 3.32 KB

slack-rs

A Rust SDK for the Slack API Platform with type-safe, idiomatic interfaces.

License Rust

Features

  • Web API Client - 287+ Slack API methods with sync and async support
  • Block Kit - Type-safe UI components (blocks, elements, views)
  • OAuth 2.0 - Complete OAuth flow with multiple storage backends
  • Socket Mode - Real-time WebSocket events with auto-reconnection
  • Webhooks - Incoming webhooks and response URLs
  • Signature Verification - HMAC-SHA256 request validation
  • HTTP Retry - Exponential backoff with rate limit handling
  • SCIM API - User/group provisioning (Enterprise)
  • Audit Logs API - Enterprise audit log access

Installation

[dependencies]
slack-rs = "0.1"
tokio = { version = "1", features = ["full"] }

Quick Start

Send a Message

use slack_rs::web::AsyncWebClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AsyncWebClient::new("xoxb-your-bot-token")?;

    let response = client.chat_post_message(
        "#general",
        "Hello from Rust!",
        None, None, None, None, None, None, None, None,
        None, None, None, None, None, None, None, None, None, None,
    ).await?;

    println!("Message sent: {:?}", response);
    Ok(())
}

Build Rich Messages with Block Kit

use slack_rs::models::*;

let blocks = vec![
    HeaderBlock::new("Daily Report")?.into(),
    DividerBlock::new().into(),
    SectionBlock::new("*Sales*: $1,234")?.into(),
    ActionsBlock::builder()
        .elements(vec![
            ButtonElement::new("View Details", "view_details")
                .with_style(ButtonStyle::Primary)
                .build()?
        ])
        .build()?
        .into(),
];

OAuth Flow

use slack_rs::oauth::AuthorizeUrlGenerator;

let generator = AuthorizeUrlGenerator::new("client_id")
    .scopes(vec!["chat:write".to_string(), "channels:read".to_string()])
    .redirect_uri("https://your-app.com/oauth/callback");

let auth_url = generator.generate("state-123", None);

Socket Mode

use slack_rs::socket_mode::SocketModeClient;

let mut client = SocketModeClient::new("xapp-your-app-token");
client.connect().await?;

Examples

See the examples/ directory for complete applications. Each example is a standalone Cargo project:

cd examples/basic_bot
SLACK_BOT_TOKEN=xoxb-your-token cargo run

Features

Optional features can be enabled in Cargo.toml:

[dependencies]
slack-rs = { version = "0.1", features = ["sqlite", "postgres", "mysql", "s3"] }
  • sqlite - SQLite storage backend (default)
  • postgres - PostgreSQL storage backend
  • mysql - MySQL storage backend
  • s3 - AWS S3 storage backend
  • full - All features

Testing

cargo test --all-features --workspace
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --check

Documentation

Requirements

  • Rust 1.75 or later

License

MIT License - see LICENSE file for details.

Acknowledgments

Inspired by the Python Slack SDK.