Files
LEANN/docs/slack-setup-guide.md
Aakash Suresh ab251ab751 Fix/twitter bookmarks anchor link (#143)
* fix: Fix Twitter bookmarks anchor link

- Convert Twitter Bookmarks from collapsible details to proper header
- Update internal link to match new anchor format
- Ensures external links to #twitter-bookmarks-your-personal-tweet-library work correctly

Fixes broken link: https://github.com/yichuan-w/LEANN?tab=readme-ov-file#twitter-bookmarks-your-personal-tweet-library

* fix: Fix Slack messages anchor link as well

- Convert Slack Messages from collapsible details to proper header
- Update internal link to match new anchor format
- Ensures external links to #slack-messages-search-your-team-conversations work correctly

Both Twitter and Slack MCP sections now have reliable anchor links.

* fix: Point Slack and Twitter links to main MCP section

- Both Slack and Twitter are subsections under MCP Integration
- Links should point to #mcp-integration-rag-on-live-data-from-any-platform
- Users will land on the MCP section and can find both Slack and Twitter subsections there

This matches the actual document structure where Slack and Twitter are under the MCP Integration section.

* Improve Slack MCP integration with retry logic and comprehensive setup guide

- Add retry mechanism with exponential backoff for cache sync issues
- Handle 'users cache is not ready yet' errors gracefully
- Add max-retries and retry-delay CLI arguments for better control
- Create comprehensive Slack setup guide with troubleshooting
- Update README with link to detailed setup guide
- Improve error messages and user experience

* Fix trailing whitespace in slack setup guide

Pre-commit hooks formatting fixes

* Add comprehensive Slack setup guide with success screenshot

- Create detailed setup guide with step-by-step instructions
- Add troubleshooting section for common issues like cache sync errors
- Include real terminal output example from successful integration
- Add screenshot showing VS Code interface with Slack channel data
- Remove excessive emojis for more professional documentation
- Document retry logic improvements and CLI arguments

* Fix formatting issues in Slack setup guide

- Remove trailing whitespace
- Fix end of file formatting
- Pre-commit hooks formatting fixes

* Add real RAG example showing intelligent Slack query functionality

- Add detailed example of asking 'What is LEANN about?'
- Show retrieved messages from Slack channels
- Demonstrate intelligent answer generation based on context
- Add command example for running real RAG queries
- Explain the 4-step process: retrieve, index, generate, cite

* Update Slack setup guide with bot invitation requirements

- Add important section about inviting bot to channels before RAG queries
- Explain the 'not_in_channel' errors and their meaning
- Provide clear steps for bot invitation process
- Document realistic scenario where bot needs explicit channel access
- Update documentation to be more professional and less cursor-style

* Docs: add real RAG example for Sky Lab #random

- Embed screenshot videos/rag-sky-random.png
- Add step-by-step commands and notes
- Include helper test script tests/test_channel_by_id_or_name.py
- Redact example tokens from docs

* Docs/CI: fix broken image paths and ruff lint\n\n- Move screenshot to docs/videos and update references\n- Remove obsolete rag-query-results image\n- Rename variable to satisfy ruff

* Docs: fix image path for lychee (use videos/ relative under docs/)

* Docs: finalize Slack setup guide with Sky random RAG example and image path fixes\n\n- Redact example tokens from docs

* Fix Slack MCP integration and update documentation

- Fix SlackMCPReader to use conversations_history instead of channels_list
- Add fallback imports for leann.interactive_utils and leann.settings
- Update slack-setup-guide.md with real screenshots and improved text
- Remove old screenshot files

* Add Slack integration screenshots to docs/videos

- Add slack_integration.png showing RAG query results
- Add slack_integration_2.png showing additional demo functionality
- Fixes lychee link checker errors for missing image files

* Update Slack integration screenshot with latest changes

* Remove test_channel_by_id_or_name.py

- Clean up temporary test file that was used for debugging
- Keep only the main slack_rag.py application for production use

* Update Slack RAG example to show LEANN announcement retrieval

- Change query from 'PUBPOL 290' to 'What is LEANN about?' for more challenging retrieval
- Update command to use python -m apps.slack_rag instead of test script
- Add expected response showing Yichuan Wang's LEANN announcement message
- Emphasize this demonstrates ability to find specific announcements in conversation history
- Update description to highlight challenging query capabilities

* Update Slack RAG integration with improved CSV parsing and new screenshots

- Fixed CSV message parsing in slack_mcp_reader.py to properly handle individual messages
- Updated slack_rag.py to filter empty channel strings
- Enhanced slack-setup-guide.md with two new query examples:
  - Advisor Models query: 'train black-box models to adopt to your personal data'
  - Barbarians at the Gate query: 'AI-driven research systems ADRS'
- Replaced old screenshots with four new ones showing both query examples
- Updated documentation to use User OAuth Token (xoxp-) instead of Bot Token (xoxb-)
- Added proper command examples with --no-concatenate-conversations and --force-rebuild flags

* Update Slack RAG documentation with Ollama integration and new screenshots

- Updated slack-setup-guide.md with comprehensive Ollama setup instructions
- Added 6 new screenshots showing complete RAG workflow:
  - Command setup, search results, and LLM responses for both queries
- Removed simulated LLM references, now uses real Ollama with llama3.2:1b
- Enhanced documentation with step-by-step Ollama installation
- Updated troubleshooting checklist to include Ollama-specific checks
- Fixed command syntax and added proper Ollama configuration
- Demonstrates working Slack RAG with real AI-generated responses

* Remove Key Features section from Slack RAG examples

- Simplified documentation by removing the bullet point list
- Keeps the focus on the actual examples and screenshots
2025-10-19 11:47:29 -07:00

12 KiB

Slack Integration Setup Guide

This guide provides step-by-step instructions for setting up Slack integration with LEANN.

Overview

LEANN's Slack integration uses MCP (Model Context Protocol) servers to fetch and index your Slack messages for RAG (Retrieval-Augmented Generation). This allows you to search through your Slack conversations using natural language queries.

Prerequisites

  1. Slack Workspace Access: You need admin or owner permissions in your Slack workspace to create apps and configure OAuth tokens.

  2. Slack MCP Server: Install a Slack MCP server (e.g., slack-mcp-server via npm)

  3. LEANN: Ensure you have LEANN installed and working

Step 1: Create a Slack App

1.1 Go to Slack API Dashboard

  1. Visit https://api.slack.com/apps
  2. Click "Create New App"
  3. Choose "From scratch"
  4. Enter your app name (e.g., "LEANN Slack Integration")
  5. Select your workspace
  6. Click "Create App"

1.2 Configure App Permissions

Token Scopes

  1. In your app dashboard, go to "OAuth & Permissions" in the left sidebar
  2. Scroll down to "Scopes" section
  3. Under "Bot Token Scopes & OAuth Scope", click "Add an OAuth Scope"
  4. Add the following scopes:
    • channels:read - Read public channel information
    • channels:history - Read messages in public channels
    • groups:read - Read private channel information
    • groups:history - Read messages in private channels
    • im:read - Read direct message information
    • im:history - Read direct messages
    • mpim:read - Read group direct message information
    • mpim:history - Read group direct messages
    • users:read - Read user information
    • team:read - Read workspace information

App-Level Tokens (Optional)

Some MCP servers may require app-level tokens:

  1. Go to "Basic Information" in the left sidebar
  2. Scroll down to "App-Level Tokens"
  3. Click "Generate Token and Scopes"
  4. Enter a name (e.g., "LEANN Integration")
  5. Add the connections:write scope
  6. Click "Generate"
  7. Copy the token (starts with xapp-)

1.3 Install App to Workspace

  1. Go to "OAuth & Permissions" in the left sidebar
  2. Click "Install to Workspace"
  3. Review the permissions and click "Allow"
  4. Copy the "Bot User OAuth Token" (starts with xoxb-)
  5. Copy the "User OAuth Token" (starts with xoxp-)

Step 2: Install Slack MCP Server

# Install globally
npm install -g slack-mcp-server

# Or install locally
npm install slack-mcp-server

Option B: Using npx (No installation required)

# Use directly without installation
npx slack-mcp-server

Step 3: Install and Configure Ollama (for Real LLM Responses)

3.1 Install Ollama

# Install Ollama using Homebrew (macOS)
brew install ollama

# Or download from https://ollama.ai/

3.2 Start Ollama Service

# Start Ollama as a service
brew services start ollama

# Or start manually
ollama serve

3.3 Pull a Model

# Pull a lightweight model for testing
ollama pull llama3.2:1b

# Verify the model is available
ollama list

Step 4: Configure Environment Variables

Create a .env file or set environment variables:

# Required: User OAuth Token
SLACK_OAUTH_TOKEN=xoxp-your-user-oauth-token-here

# Optional: App-Level Token (if your MCP server requires it)
SLACK_APP_TOKEN=xapp-your-app-token-here

# Optional: Workspace-specific settings
SLACK_WORKSPACE_ID=T1234567890  # Your workspace ID (optional)

Step 5: Test the Setup

5.1 Test MCP Server Connection

python -m apps.slack_rag \
  --mcp-server "slack-mcp-server" \
  --test-connection \
  --workspace-name "Your Workspace Name"

This will test the connection and list available tools without indexing any data.

5.2 Index a Specific Channel

python -m apps.slack_rag \
  --mcp-server "slack-mcp-server" \
  --workspace-name "Your Workspace Name" \
  --channels general \
  --query "What did we discuss about the project?"

5.3 Real RAG Query Examples

This section demonstrates successful Slack RAG integration queries against the Sky Lab Computing workspace's "random" channel. The system successfully retrieves actual conversation messages and performs semantic search with high relevance scores, including finding specific research paper announcements and technical discussions.

Example 1: Advisor Models Query

Query: "train black-box models to adopt to your personal data"

This query demonstrates the system's ability to find specific research announcements about training black-box models for personal data adaptation.

Advisor Models Query - Command Setup

Advisor Models Query - Search Results

Advisor Models Query - LLM Response

Example 2: Barbarians at the Gate Query

Query: "AI-driven research systems ADRS"

This query demonstrates the system's ability to find specific research announcements about AI-driven research systems and algorithm discovery.

Barbarians Query - Command Setup

Barbarians Query - Search Results

Barbarians Query - LLM Response

Prerequisites

  • Bot is installed in the Sky Lab Computing workspace and invited to the target channel (run /invite @YourBotName in the channel if needed)
  • Bot token available and exported in the same terminal session

Commands

  1. Set the workspace token for this shell
export SLACK_MCP_XOXP_TOKEN="xoxp-***-redacted-***"
  1. Run queries against the "random" channel by channel ID (C0GN5BX0F)

Advisor Models Query:

python -m apps.slack_rag \
  --mcp-server "slack-mcp-server" \
  --workspace-name "Sky Lab Computing" \
  --channels C0GN5BX0F \
  --max-messages-per-channel 100000 \
  --query "train black-box models to adopt to your personal data" \
  --llm ollama \
  --llm-model "llama3.2:1b" \
  --llm-host "http://localhost:11434" \
  --no-concatenate-conversations

Barbarians at the Gate Query:

python -m apps.slack_rag \
  --mcp-server "slack-mcp-server" \
  --workspace-name "Sky Lab Computing" \
  --channels C0GN5BX0F \
  --max-messages-per-channel 100000 \
  --query "AI-driven research systems ADRS" \
  --llm ollama \
  --llm-model "llama3.2:1b" \
  --llm-host "http://localhost:11434" \
  --no-concatenate-conversations

These examples demonstrate the system's ability to find and retrieve specific research announcements and technical discussions from the conversation history, showcasing the power of semantic search in Slack data.

  1. Optional: Ask a broader question
python test_channel_by_id_or_name.py \
  --channel-id C0GN5BX0F \
  --workspace-name "Sky Lab Computing" \
  --query "What is LEANN about?"

Notes:

  • If you see not_in_channel, invite the bot to the channel and re-run.
  • If you see channel_not_found, confirm the channel ID and workspace.
  • Deep search via server-side “search” tools may require additional Slack scopes; the example above performs client-side filtering over retrieved history.

Common Issues and Solutions

Issue 1: "users cache is not ready yet" Error

Problem: You see this warning:

WARNING - Failed to fetch messages from channel random: Failed to fetch messages: {'code': -32603, 'message': 'users cache is not ready yet, sync process is still running... please wait'}

Solution: This is a common timing issue. The LEANN integration now includes automatic retry logic:

  1. Wait and Retry: The system will automatically retry with exponential backoff (2s, 4s, 8s, etc.)
  2. Increase Retry Parameters: If needed, you can customize retry behavior:
    python -m apps.slack_rag \
      --mcp-server "slack-mcp-server" \
      --max-retries 10 \
      --retry-delay 3.0 \
      --channels general \
      --query "Your query here"
    
  3. Keep MCP Server Running: Start the MCP server separately and keep it running:
    # Terminal 1: Start MCP server
    slack-mcp-server
    
    # Terminal 2: Run LEANN (it will connect to the running server)
    python -m apps.slack_rag --mcp-server "slack-mcp-server" --channels general --query "test"
    

Issue 2: "No message fetching tool found"

Problem: The MCP server doesn't have the expected tools.

Solution:

  1. Check if your MCP server is properly installed and configured
  2. Verify your Slack tokens are correct
  3. Try a different MCP server implementation
  4. Check the MCP server documentation for required configuration

Issue 3: Permission Denied Errors

Problem: You get permission errors when trying to access channels.

Solutions:

  1. Check Bot Permissions: Ensure your bot has been added to the channels you want to access
  2. Verify Token Scopes: Make sure you have all required scopes configured
  3. Channel Access: For private channels, the bot needs to be explicitly invited
  4. Workspace Permissions: Ensure your Slack app has the necessary workspace permissions

Issue 4: Empty Results

Problem: No messages are returned even though the channel has messages.

Solutions:

  1. Check Channel Names: Ensure channel names are correct (without the # symbol)
  2. Verify Bot Access: Make sure the bot can access the channels
  3. Check Date Ranges: Some MCP servers have limitations on message history
  4. Increase Message Limits: Try increasing the message limit:
    python -m apps.slack_rag \
      --mcp-server "slack-mcp-server" \
      --channels general \
      --max-messages-per-channel 1000 \
      --query "test"
    

Advanced Configuration

Custom MCP Server Commands

If you need to pass additional parameters to your MCP server:

python -m apps.slack_rag \
  --mcp-server "slack-mcp-server --token-file /path/to/tokens.json" \
  --workspace-name "Your Workspace" \
  --channels general \
  --query "Your query"

Multiple Workspaces

To work with multiple Slack workspaces, you can:

  1. Create separate apps for each workspace
  2. Use different environment variables
  3. Run separate instances with different configurations

Performance Optimization

For better performance with large workspaces:

python -m apps.slack_rag \
  --mcp-server "slack-mcp-server" \
  --workspace-name "Your Workspace" \
  --max-messages-per-channel 500 \
  --no-concatenate-conversations \
  --query "Your query"

Troubleshooting Checklist

  • Slack app created with proper permissions
  • Bot token (xoxb-) copied correctly
  • App-level token (xapp-) created if needed
  • MCP server installed and accessible
  • Ollama installed and running (brew services start ollama)
  • Ollama model pulled (ollama pull llama3.2:1b)
  • Environment variables set correctly
  • Bot invited to relevant channels
  • Channel names specified without # symbol
  • Sufficient retry attempts configured
  • Network connectivity to Slack APIs

Getting Help

If you continue to have issues:

  1. Check Logs: Look for detailed error messages in the console output
  2. Test MCP Server: Use --test-connection to verify the MCP server is working
  3. Verify Tokens: Double-check that your Slack tokens are valid and have the right scopes
  4. Check Ollama: Ensure Ollama is running (ollama serve) and the model is available (ollama list)
  5. Community Support: Reach out to the LEANN community for help

Example Commands

Basic Usage

# Test connection
python -m apps.slack_rag --mcp-server "slack-mcp-server" --test-connection

# Index specific channels
python -m apps.slack_rag \
  --mcp-server "slack-mcp-server" \
  --workspace-name "My Company" \
  --channels general random \
  --query "What did we decide about the project timeline?"

Advanced Usage

# With custom retry settings
python -m apps.slack_rag \
  --mcp-server "slack-mcp-server" \
  --workspace-name "My Company" \
  --channels general \
  --max-retries 10 \
  --retry-delay 5.0 \
  --max-messages-per-channel 2000 \
  --query "Show me all decisions made in the last month"