Crate slacko

Crate slacko 

Source
Expand description

§Slack SDK

A comprehensive Rust SDK for the Slack API with support for both stealth mode (xoxc/xoxd tokens) and regular OAuth tokens (xoxp/xoxb).

§Features

  • Multiple Authentication Methods: OAuth tokens (xoxp, xoxb) and stealth mode (xoxc/xoxd)
  • Complete API Coverage: 24 API modules covering all Slack functionality
  • Real-time Messaging: RTM API support via WebSocket
  • Block Kit Support: Builders for rich message layouts
  • Type Safety: Strongly typed API responses and requests
  • Async/Await: Built on tokio for high-performance async operations
  • Rate Limit Handling: Automatic detection with retry information

§Quick Start

use slacko::{SlackClient, AuthConfig};

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

    // Post a message
    client.chat().post_message("#general", "Hello from Rust!").await?;

    // List channels
    let channels = client.conversations().list().await?;
    for channel in channels.channels {
        println!("#{}", channel.name.unwrap_or_default());
    }

    Ok(())
}

§Authentication

§OAuth Tokens

use slacko::{SlackClient, AuthConfig};

// Bot token (xoxb-...)
let client = SlackClient::new(AuthConfig::bot("xoxb-token")).unwrap();

// User token (xoxp-...)
let client = SlackClient::new(AuthConfig::oauth("xoxp-token")).unwrap();

§Stealth Mode

Stealth mode uses browser session tokens and does not require app installation:

use slacko::{SlackClient, AuthConfig};

let client = SlackClient::new(
    AuthConfig::stealth("xoxc-token", "xoxd-cookie")
).unwrap();

§Environment Variables

The SDK can auto-detect credentials from environment variables:

use slacko::{SlackClient, AuthConfig};

// Checks SLACK_XOXC_TOKEN/SLACK_XOXD_COOKIE, then SLACK_XOXP_TOKEN, then SLACK_BOT_TOKEN
let client = SlackClient::new(AuthConfig::from_env().unwrap()).unwrap();

§API Modules

The SDK provides access to all major Slack APIs:

§Block Kit

Build rich messages using Block Kit builders:

use slacko::{SlackClient, AuthConfig, MessageBuilder};

let client = SlackClient::new(AuthConfig::bot("xoxb-token")).unwrap();

let blocks = MessageBuilder::new()
    .section("*Hello* from Block Kit")
    .divider()
    .build();

// client.chat().post_message_with_blocks("#general", "Hello", blocks).await?;

§Error Handling

The SDK provides detailed error types:

use slacko::{SlackClient, AuthConfig, SlackError};

async fn example() {
    let client = SlackClient::new(AuthConfig::bot("xoxb-token")).unwrap();

    match client.chat().post_message("#general", "Hello").await {
        Ok(response) => println!("Message sent: {}", response.ts),
        Err(SlackError::RateLimitExceeded { retry_after }) => {
            println!("Rate limited, retry after {} seconds", retry_after);
        }
        Err(SlackError::ApiError { code, message }) => {
            println!("API error {}: {}", code, message);
        }
        Err(e) => println!("Error: {}", e),
    }
}

Re-exports§

pub use auth::AuthConfig;
pub use auth::AuthType;
pub use client::SlackClient;
pub use error::Result;
pub use error::SlackError;
pub use blocks::ActionsBlock;
pub use blocks::ButtonElement;
pub use blocks::ConfirmationDialog;
pub use blocks::ContextBlock;
pub use blocks::DividerBlock;
pub use blocks::HeaderBlock;
pub use blocks::ImageBlock;
pub use blocks::MessageBuilder;
pub use blocks::OptionObject;
pub use blocks::SectionBlock;
pub use blocks::SelectElement;
pub use blocks::TextObject;
pub use types::Channel;
pub use types::Message;
pub use types::ResponseMetadata;
pub use types::User;
pub use api::conversations::ConversationHistoryRequest;
pub use api::users::UsersListRequest;

Modules§

api
Slack API endpoint modules
auth
Authentication configuration for Slack API
blocks
Block Kit builders
client
Core Slack API client
error
Error types for the Slack SDK
types
Common types used across the Slack SDK