A Slack bot that copies thread conversations, generates Jira stories, and formats them for easy sharing.
- Copy entire thread conversations with the
!copytcommand. - Generate a Jira story from a thread with the
!genstorycommand using OpenAI or Gemini. - Includes a permanent link to the original Slack thread in the output.
- Cleans formatting by removing Slack-specific markup.
- Debug mode for easy troubleshooting.
- Comprehensive logging.
-
Clone the repository:
git clone https://github.com/chmouel/slack-thread-bot.git cd slack-thread-bot -
Install dependencies: This project uses
uvfor package management.uv sync
-
Configure environment variables: Copy the example
.envfile and fill in your Slack and LLM provider tokens.cp .env.example .env
Then edit
.envwith your actual tokens. See the "Environment Variables" section for details. -
Run the bot:
uv run main.py
The bot will connect to Slack and be ready for commands!
SLACK_BOT_TOKEN: Your Slack bot token (starts withxoxb-).SLACK_APP_TOKEN: Your Slack app token (starts withxapp-).DEBUG: Enable debug mode (true,1,yes,onfor enabled).LLM_PROVIDER: The desired LLM provider. Can beopenaiorgemini(default).OPENAI_API_KEY: Your OpenAI API key (if usingopenai).OPENAI_MODEL: The OpenAI model to use (e.g.,gpt-3.5-turbo).GEMINI_API_KEY: Your Gemini API key (if usinggemini).GEMINI_MODEL: The Gemini model to use (defaults togemini-2.5-flash).CACHE_STORY_DIR: (Optional) If set, the generated user story will be cached to this directory.BATZ_BASE_TZ: (Optional) The base timezone for the!tzcommand. Defaults toUTC.BATZ_TIMEZONES: (Optional) A comma-separated list of default timezones to display when no airport codes are provided in the!tzcommand. The format isName/IANA_Timezone(e.g.,Paris/Europe/Paris,Tokyo/Asia/Tokyo).BATZ_EMOJIS: (Optional) A comma-separated list of emoji mappings for the timezones. The format isName/:emoji:orAirportCode/:emoji:. TheNamemust match the name provided inBATZ_TIMEZONES. For example,Paris/:fr:,BLR/:flag-in:.
This bot can integrate with either OpenAI or Gemini to generate Jira stories from Slack threads using the !genstory command.
To configure the LLM provider, set the LLM_PROVIDER environment variable to either openai or gemini.
If LLM_PROVIDER is set to openai (or is unset), you must provide:
OPENAI_API_KEY: Your OpenAI API key.OPENAI_MODEL: (Optional) The model to use (defaults togpt-3.5-turbo).
If LLM_PROVIDER is set to gemini, you must provide:
GEMINI_API_KEY: Your Google AI Studio API key.GEMINI_MODEL: (Optional) The model to use (defaults togemini-pro).
- Invite the bot to your Slack channel.
- In any message thread, use one of the following commands:
!copyt: The bot will format and send you a direct message with the entire thread conversation, including a link to the original thread.!genstory: The bot will use an LLM (OpenAI or Gemini) to generate a Jira story from the thread conversation and send it to you as a snippet in a direct message. The story will also include a link to the original thread.!actions: The bot will use an LLM to extract a list of action items from the thread and post them as a reply in the thread.!tz <time> [airport codes]: The bot will convert the specified time.- If airport codes (3-letter IATA codes) are provided, it will convert the time to the corresponding timezones. You can provide multiple codes separated by commas.
- If no airport codes are provided, it will use the default timezones specified in the
BATZ_TIMEZONESenvironment variable. - Examples:
!tz 10h00!tz 10:30 tomorrow!tz 5pm next monday!tz now(or just!tz)!tz 10h00 BLR,CDG!tz tomorrow 10:00 NY
For the bot to function correctly, your Slack App needs the following permissions (scopes):
channels:history: View messages in public channels the bot is in.groups:history: View messages in private channels the bot is in.chat:write: Send messages as the bot.files:write: Upload files as snippets for DMs.im:write: Start direct messages with users.reactions:write: Add emoji reactions to messages.users:read: View user information to resolve display names.
Enable debug mode by setting the DEBUG environment variable:
export DEBUG=true
python main.pyOr run with debug mode temporarily:
DEBUG=true python main.pyDebug mode provides:
- Detailed logging to console and
/tmp/slack-bot-debug.logfile. - Step-by-step processing information.
- Environment variable validation.
- Enhanced error messages with stack traces.
If the bot doesn't respond:
- Enable debug mode to see detailed logs.
- Check that all required environment variables are set correctly.
- Verify the bot has the correct permissions in your Slack workspace (see above).
- Check the console output for error messages.