Pennyworth is an elegant Slack assistant that combines AI capabilities, Trello integration, and team management features into a helpful digital butler. Styled after Batman's faithful companion Alfred Pennyworth, the bot responds with formal, dignified replies while providing useful functionality for your team.
AI-Powered Assistance
- Natural language responses using Google Gemini AI
- Contextual chat memory with persona-based responses
- Command prefix (
!ai
) for direct AI queries
Trello Workflow Management
- Create and manage cards with
!trello
commands - Move cards between lists
- Add comments to cards
- List available boards and lists
Team Management
- Personalized new user onboarding
- Automated welcome messages
- Conversation summarization
- Response to mentions in channels
Slack Integration
- Socket Mode connectivity
- Direct message interactions
- Channel mentions with
@Pennyworth
- Message commands with prefix (
!command
)
┌─────────────────┐ ┌───────────────┐ ┌───────────────┐
│ │ │ │ │ │
│ Slack Platform ├──────┤ Cloud Run ├──────┤ Google │
│ │ │ Container │ │ Gemini AI │
└─────────────────┘ └──────┬────────┘ └───────────────┘
│
│
┌──────┴────────┐
│ │
│ Trello API │
│ │
└───────────────┘
- Google Cloud Platform
- Cloud Run service
- Container Registry (GCR or Artifact Registry)
- Service Account with proper permissions
- Google Cloud Platform
- Bot Token (
xoxb-*
) - Required for posting messages - App Token (
xapp-*
) - Required for Socket Mode - Signing Secret - For request verification
- Bot Token (
- Google Cloud Platform
- API Key
- API Secret
- Token
- Google AI
- Gemini API Key
- GitHub CLI Authentication (for semantic release)
- Personal access token with
repo
scope - SSH key for Git operations (optional)
- Personal access token with
-
Create a Slack App
- Go to [api.slack.com/apps]
- Click "Create New App" and choose "From scratch"
- Name your app "Pennyworth" and select your workspace
-
Configure Bot User
- Navigate to "App Home"
- Enable "Always Show My Bot as Online"
- Enable "Messages Tab"
- Check "Allow users to send messages in the app home"
-
OAuth & Permissions
-
Go to "OAuth & Permissions"
-
Add these Bot Token Scopes:
app_mentions:read
- Detect @mentions of your botchannels:history
- Read messages in public channelschannels:join
- Join public channelschannels:read
- View public channelschat:write
- Send messageschat:write.public
- Send messages to public channelsgroups:history
- Read messages in private channelsgroups:read
- View private channelsim:history
- Read direct messagesim:read
- View direct messagesim:write
- Send direct messagesmpim:history
- Read group direct messagesmpim:read
- View group direct messagesmpim:write
- Send group direct messagesreactions:read
- View reactionsreactions:write
- Add/remove reactionsteam:read
- View basic team infousers:read
- View user profilesusers:read.email
- View email addresses
-
Add these User Token Scopes:
chat:write:user
- Send messages as userusers.profile:read
- View user profiles in detail
-
-
Event Subscriptions
- Go to "Event Subscriptions" and enable
- Subscribe to these bot events:
app_mention
- When someone @mentions your botmessage.channels
- Messages in public channelsmessage.groups
- Messages in private channelsmessage.im
- Direct messages to your botmessage.mpim
- Messages in group DMs with your botteam_join
- When new users join the workspacechannel_created
- When a channel is createdchannel_archive
- When a channel is archivedchannel_unarchive
- When a channel is unarchivedmember_joined_channel
- When users join a channelmember_left_channel
- When users leave a channel
-
Socket Mode
- Go to "Socket Mode" and enable
- Create an app-level token with
connections:write
scope - Note the token starting with
xapp-
-
Install to Workspace
- Go to "Install App"
- Click "Install to Workspace" and authorize
# Clone repository
git clone https://github.com/yourusername/pennyworth-slack-bot.git
cd pennyworth-slack-bot
# Create conda environment
conda create -n pennyworth python=3.11
conda activate pennyworth
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your secret tokens
# Slack Configuration
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_APP_TOKEN=xapp-your-app-token
SLACK_SIGNING_SECRET=your-signing-secret
# Trello Configuration
TRELLO_API_KEY=your-trello-key
TRELLO_API_SECRET=your-trello-secret
TRELLO_TOKEN=your-trello-token
# Google AI Configuration
GOOGLE_GEMINI_API_KEY=your-gemini-key
# Application Configuration
TIMEZONE=America/New_York
LOG_LEVEL=INFO
pennyworth-slack-bot/
│
├── src/ # Source code directory
│ ├── __init__.py # Version information
│ ├── bot.py # Main Slack bot logic
│ ├── ai_assistant.py # Gemini AI integration
│ ├── trello_workflows.py # Trello workflow handlers
│ └── utils/ # Utility modules
│ └── __init__.py
│
├── server.py # Cloud Run server & health checks
│
├── .github/ # GitHub Actions workflows
│ └── workflows/
│ ├── slack-bot-deploy.yml # Main deployment workflow
│ └── py-semantic-release.yml # Versioning workflow
│
├── .env.example # Example environment variables
├── Dockerfile # Container definition
├── requirements.txt # Project dependencies
├── pyproject.toml # Semantic versioning config
├── CHANGELOG.md # Automatically generated changelog
└── README.md # Project documentation
# Export your GitHub token for semantic-release
export GH_TOKEN=$(gh auth token)
# Update version based on conventional commits
semantic-release version
# Run the bot locally
python server.py
The project uses GitHub Actions for CI/CD:
- Push changes to the main branch
- The py-semantic-release workflow updates version and changelog
- The slack-bot-deploy workflow:
- Builds a Docker container
- Pushes to GitHub Container Registry
- Copies to Google Container Registry
- Deploys to Cloud Run
- Sends notification to Slack
# Build container
docker build -t pennyworth-bot:latest .
# Test locally
docker run -p 8080:8080 --env-file .env pennyworth-bot:latest
# Deploy to Cloud Run
gcloud run deploy pennyworth-bot \
--image gcr.io/your-project/pennyworth-bot:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated
Start a conversation with Pennyworth in DMs:
hello
- Get a greeting!ai [question]
- Ask AI a question!summarize
- Summarize recent conversation!trello
boards - List available Trello boards
Add Pennyworth to a channel and:
@Pennyworth [question]
- Mention to ask a question!ai [question]
- Use the AI command!trello create [title] in [list]
- Create a Trello card
- Verify Socket Mode is enabled
- Check that event subscriptions are configured
- Confirm the app tokens start with
xoxb-
andxapp-
- Look at Cloud Run logs for connection errors
- Ensure the bot is added to the channel
- Check event subscriptions include
app_mention
andmessage.*
- Verify the bot has proper OAuth scopes
- Inspect Cloud Run logs for any errors
- Check the GitHub Actions workflow logs
- Verify environment variables are correctly set
- Ensure service account has proper permissions
Please follow Conventional Commits format for all commits to ensure proper semantic versioning:
feat: add new feature
(triggers minor version bump)fix: resolve bug
(triggers patch version bump)docs: update documentation
(no version bump)chore: update dependencies
(no version bump)