Skip to content

defi-space/ds-slack

Repository files navigation

DS Slack Bot

A Slack bot that integrates with Groq AI and Jira to create tasks from Slack threads. The bot uses Groq's deepseek-r1-distill-llama-70b model for intelligent task title and description generation with AI-powered categorization and repository context integration.

Features

  • AI Categorization System: Automatically categorizes requests into frontend, docs, agents, contracts, or indexer
  • GitHub Repository Integration: Fetches repository context using UitHub API for enhanced issue generation
  • Enhanced LLM Context: Uses repository structure and category-specific guidance for better task descriptions
  • AI-powered task title and description generation using Groq's deepseek-r1-distill-llama-70b model
  • Automatic sprint assignment for non-backlog tasks
  • Beautiful unicode-styled confirmation messages with category and repository information
  • Git command suggestions for new task branches
  • Thread-based context gathering for better task descriptions
  • User mapping between Slack and Jira for automatic assignee handling
  • Support for both socket mode and HTTP server mode
  • Automatic priority assignment (default: Medium)
  • Comprehensive error handling and logging

Prerequisites

  • Bun installed on your system
  • Slack workspace with:
    • Bot Token (xoxb-*)
    • App-Level Token (xapp-*) for Socket Mode
    • Signing Secret
  • Groq API Key
  • GitHub Personal Access Token (for private repositories)
  • Jira Cloud instance with:
    • API Token
    • Project configured with sprints
    • Custom field for sprint assignment

Setup

  1. Install dependencies:

    bun install
  2. Copy the example environment file and configure your variables:

    cp .env.example .env
  3. Configure environment variables in .env file:

    # Slack Configuration
    SLACK_BOT_TOKEN=xoxb-your-slack-bot-token
    SLACK_SIGNING_SECRET=your-slack-signing-secret
    SLACK_APP_TOKEN=xapp-your-slack-app-level-token-for-socket-mode
    
    # Groq API Configuration
    GROQ_API_KEY=your-groq-api-key
    
    # GitHub Configuration
    GITHUB_PAT=your-github-personal-access-token
    
    # Allowed User IDs (comma-separated Slack User IDs)
    ALLOWED_USER_IDS=U1234,U5678
    
    # Jira Configuration
    JIRA_BASE=https://your-org.atlassian.net
    JIRA_EMAIL=your-email@org.com
    JIRA_API_TOKEN=your-jira-api-token
    CUSTOM_SPRINT_FIELD=customfield_10007
    
    # Slack User ID to Jira Account ID Mapping (JSON string)
    SLACK_TO_JIRA_MAP={"U1234":"712020:user1","U5678":"712020:user2"}
    
    # Application Port (for HTTP mode)
    PORT=4207
  4. Build the TypeScript code:

    bun run build
  5. Start the development server:

    bun run dev

    Or for production:

    bun run start

Development

The project uses Bun for fast TypeScript execution and package management. Available commands:

  • bun run dev - Start development server with hot reload
  • bun run build - Build production bundle
  • bun run start - Start production server
  • bun run lint - Run ESLint checks
  • bun run lint:fix - Fix ESLint issues
  • bun run format - Format code with Prettier
  • bun run format:check - Check code formatting
  • bun run types - Check TypeScript types
  • bun run types:watch - Watch and check TypeScript types

Usage

Mention the bot in a Slack thread with the following options:

  • @username - Assign the task to a specific user
  • backlog or back log - Skip sprint assignment and place in backlog

Examples:

@dst-bot @valentin backlog Update documentation
@dst-bot @charles Implement new feature
@dst-bot Fix critical bug

The bot will:

  1. Analyze and categorize the thread context using AI
  2. Fetch repository context based on the determined category
  3. Generate enhanced task title and description using repository-aware prompts
  4. Create a Jira ticket with appropriate assignments
  5. Return a formatted message with:
    • Issue key and title
    • Category and confidence level
    • Target repository
    • Assignee
    • Jira URL
    • Git branch creation command
    • Git commit message format

Deployment

For systemd-based deployments, use the provided dst-bot.service file:

  1. Copy the service file:

    sudo cp dst-bot.service /etc/systemd/system/
  2. Enable and start the service:

    sudo systemctl enable dst-bot
    sudo systemctl start dst-bot

The service will:

  • Run in the /root/ds-slack directory
  • Use Bun to execute the server
  • Auto-restart on failures
  • Load environment variables from .env
  • Log to systemd journal

Architecture

The bot is built with:

  • TypeScript for type safety
  • @slack/bolt for Slack integration
  • @ai-sdk/groq for AI processing
  • axios for HTTP requests
  • marklassian for Markdown to Atlassian Document Format conversion
  • dotenv for environment management

Key components:

  • src/server.ts - Main application entry point
  • src/worker.ts - Core task processing logic with enhanced categorization
  • src/genai.ts - Groq AI integration with categorization and enhanced context
  • src/repository.ts - UitHub API integration for repository context
  • src/config.ts - Configuration management with repository mappings
  • src/types.ts - TypeScript type definitions for new features

License

Internal use only - DefiSpace

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •