Skip to main content

Slack Joke Agent

An agent that sends jokes and trivia to your Slack channel daily. jokes

Features

  • AI-Generated Content - Fresh jokes and trivia powered by Claude AI
  • Science/tech jokes (60% of messages) and history trivia facts (40% of messages)
  • Automated posting at 9:00 AM daily (configurable)
  • Uses MCP Slack server integration
  • Target channel configurable

Setup

  1. Configure environment variables:

    cp .env.example .env
    # Edit .env with your Slack bot tokens
    

    Create a Slack app at https://api.slack.com/apps to get the bot token.

  2. Install dependencies:

    pip install -e .
    
  3. Or use the startup script:

    ./start-agent.sh
    

Usage

Start the daily agent:

python slack_agent.py

Start with custom time:

python slack_agent.py --time 12:00  # Daily at noon

Test with immediate message:

python slack_agent.py --test
python slack_agent.py --test-ai

Use custom channel:

python slack_agent.py --channel C1234567890

Enable verbose logging:

python slack_agent.py --verbose

How it Works

  1. Scheduling: Uses Python schedule library to trigger daily at 9:00 AM
  2. AI Generation: Uses Anthropic's Claude AI to generate fresh content
  3. Content Selection: Randomly selects between jokes and trivia (60%/40% split)
  4. Fallback System: Uses predefined content if AI generation fails
  5. MCP Integration: Spawns the MCP Slack server process
  6. Channel: Posts to #random channel by default
  7. Logging: Logs to both console and slack_agent.log file

Configuration

Environment variables in .env file:

Required:

  • SLACK_BOT_TOKEN - Your Slack bot token (xoxb-...)
  • SLACK_TEAM_ID - Your Slack team/workspace ID
  • DEFAULT_CHANNEL_ID - Default channel to post
  • ANTHROPIC_API_KEY - Your Anthropic API key for Claude AI (sk-ant-...)

Optional:

  • SLACK_CHANNEL_IDS - Comma-separated list of allowed channels

Security:

  • All secrets loaded from .env file (excluded from git)
  • No hardcoded API keys or tokens in source code
  • Environment variable validation on startup
  • Graceful handling of missing AI credentials

Command Line Options

  • --test: Send a test message immediately
  • --test-ai: Test AI generation without sending to Slack
  • --channel CHANNEL_ID: Override the default channel
  • --time HH:MM: Set daily schedule time (default: 09:00)
  • --verbose, -v: Enable verbose debug logging

Logs

The agent creates comprehensive logs:

  • Console output: Real-time status and messages
  • File logging: slack_agent.log with detailed information
  • Timestamps: All log entries include precise timestamps
  • Error tracking: Failed attempts are logged with details

Customization

Add more jokes/trivia:

Edit the jokes and trivia lists in slack_agent.py

Change schedule:

Modify the schedule configuration:

schedule.every().day.at("09:00").do(self.send_daily_message)  # Daily at 9 AM (current)
schedule.every().day.at("12:00").do(self.send_daily_message)  # Daily at noon
schedule.every().hour.at(":00").do(self.send_daily_message)   # Every hour
schedule.every().monday.at("09:00").do(self.send_daily_message)  # Weekly on Monday

Change channel:

Update the channel_id property or use --channel argument

Installation

pip install slack-joke-agent
slack-agent --help

From Source:

git clone https://github.com/wangjing0/slack-joke-agent.git
cd slack-joke-agent
pip install -e .

Quick Development Setup:

git clone https://github.com/wangjing0/slack-joke-agent.git
cd slack-joke-agent
./start-agent.sh

Running Tests:

python test_slack_agent.py

Contributing

Contributions are welcome! Please feel free to submit a pull request. ❤️

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for slack-joke-agent 1.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slack-joke-agent 1.1.7
File Size Uploaded Provenance
slack_joke_agent-1.1.7.tar.gz 14.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for slack-joke-agent 1.1.7
File Interpreter ABI Platform
slack_joke_agent-1.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 22.9 kB

Release files / slack_joke_agent-1.1.7.tar.gz

Download URL slack_joke_agent-1.1.7.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2c4489fc507a3b1617dded1ba1e2e8629d506d3e6e9cd6e2bca2287e9b56ad88
BLAKE2b-256 checksum
How to use checksums
56a7608b29f012593ecf5b2e53529aa2bdd3325c441a0f1a38f1dab20e63a506
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Release files / slack_joke_agent-1.1.7-py3-none-any.whl

Download URL slack_joke_agent-1.1.7-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b22e86155463e78ebc87b45d5415d7a6696d6b18ff220320422d289c4197c6e
BLAKE2b-256 checksum
How to use checksums
8bea52384d218c0d3f7fe5b64c8851fcc4285901591e664c48edc08fe0f744bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Security for slack-joke-agent 1.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page