A Slack bot that records and wishes Slack workspace members a happy birthday with AI-generated personalized messages.
- Birthday Recording: Users can set their birthdays via DM to the bot
- Birthday Announcements: Automatic birthday celebrations in a designated channel
- AI-Generated Messages: Personalized birthday wishes using OpenAI
- Historical Date Facts: Includes interesting scientific and historical facts about the birthday date
- Admin Commands: Statistics, user management, and settings
- System Health Monitoring: Built-in diagnostics for troubleshooting
- Data Management: Automated backups and recovery options
- Reminders: Automatically remind users who haven't set their birthday
- Multiple Personalities: Switch between different bot personalities with persistent settings
- Custom Templates: Fully customizable message templates for each personality
brightdaybot/
├── app.py # Main entry point
├── config.py # Configuration and environment settings
├── data/ # Data directory
│ ├── logs/ # Log files
│ ├── storage/ # Birthday data and configuration
│ ├── tracking/ # Announcement tracking
│ ├── cache/ # Cache for web search results
│ └── backups/ # Backup files
├── handlers/ # Slack event and command handlers
│ ├── command_handler.py # Command processing logic
│ └── event_handler.py # Event handling logic
├── services/ # Core functionality
│ ├── birthday.py # Birthday management logic
│ └── scheduler.py # Scheduling functionality
└── utils/ # Helper modules
├── config_storage.py # Configuration storage
├── date_utils.py # Date handling functions
├── message_generator.py # Message generation using OpenAI
├── web_search.py # Web search for birthday facts
├── slack_utils.py # Slack API wrapper functions
└── storage.py # Birthday storage functions
Follow these steps to set up BrightDayBot.
- Go to https://api.slack.com/apps and click "Create New App"
- Choose "From scratch" and give it a name (e.g., "BrightDayBot")
- Select your workspace
- Under "Add features and functionality":
- Enable "Socket Mode"
- Enable "Event Subscriptions" and subscribe to:
message.im
(for direct messages)team_join
(for new user onboarding)
- Add "Bot Token Scopes" under "OAuth & Permissions":
chat:write
users:read
users.profile:read
im:history
im:write
channels:read
groups:read
mpim:read
users:read.email
- Install the app to your workspace and copy the bot token (
xoxb-...
) - Generate an app-level token with
connections:write
scope and copy it (xapp-...
)
This bot has been tested with Python 3.12, but might work with earlier versions.
Before running the bot, make sure you have generated SSL certificates within your Python installation.
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
Create a .env file in the project root:
SLACK_APP_TOKEN="xapp-your-app-token"
SLACK_BOT_TOKEN="xoxb-your-bot-token"
BIRTHDAY_CHANNEL_ID="C0123456789"
OPENAI_API_KEY="sk-your-openai-api-key"
OPENAI_MODEL="gpt-4o" # Optional: defaults to gpt-4o
# Optional: Custom bot personality settings
CUSTOM_BOT_NAME="Birthday Wizard"
CUSTOM_BOT_DESCRIPTION="a magical birthday celebration wizard"
CUSTOM_BOT_STYLE="magical, whimsical, and full of enchantment"
CUSTOM_FORMAT_INSTRUCTION="Create a magical spell-like birthday message"
CUSTOM_BOT_TEMPLATE_EXTENSION="Your custom template extension here"
# Optional: Web search caching (defaults to enabled)
WEB_SEARCH_CACHE_ENABLED="true" # Set to "false" to disable caching
Execute the main Python script:
python app.py
The bot will:
- Create necessary data directories (logs, storage, tracking, backups)
- Initialize configuration from storage or create default settings
- Store birthdays in data/storage/birthdays.txt
- Store configuration in data/storage/*.json files
- Write logs to data/logs/app.log
- Check for today's birthdays at startup
- Schedule daily birthday checks at 8:00 AM UTC
To run BrightDayBot as a persistent service that starts automatically after reboots:
-
Create a systemd service file:
sudo nano /etc/systemd/system/brightdaybot.service
With content:
[Unit] Description=BrightDayBot Service After=network.target [Service] Type=simple ExecStart=/path/to/venv/bin/python /path/to/brightdaybot/app.py WorkingDirectory=/path/to/brightdaybot User=your_username Group=your_group Restart=always [Install] WantedBy=multi-user.target
-
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable brightdaybot.service sudo systemctl start brightdaybot.service
-
Manage the bot service:
# Check status sudo systemctl status brightdaybot.service # Restart the bot sudo systemctl restart brightdaybot.service # View logs sudo journalctl -u brightdaybot.service -f
When you update the code or configuration:
# Pull latest changes
cd /path/to/brightdaybot
git pull
# Restart the service
sudo systemctl restart brightdaybot.service
DM the bot with any of these commands:
help
- Show help informationadd DD/MM
- Add birthday without yearadd DD/MM/YYYY
- Add birthday with yearremove
- Remove your birthdaycheck
- Check your saved birthdaycheck @user
- Check someone else's birthdaytest
- See a test birthday message
Or simply send a date in DD/MM
or DD/MM/YYYY
format.
admin list
- List configured admin usersadmin add USER_ID
- Add a user as adminadmin remove USER_ID
- Remove admin privilegeslist
- List upcoming birthdayslist all
- List all birthdays by monthstats
- View birthday statisticsadmin status
- Check system health and component statusadmin status detailed
- Get detailed system informationremind [message]
- Send reminders to users without birthdaysconfig
- View command permissionsconfig COMMAND true/false
- Change command permissionsadmin backup
- Create a manual backup of birthdays dataadmin restore latest
- Restore from the latest backupadmin cache clear
- Clear all web search cacheadmin cache clear DD/MM
- Clear web search cache for a specific date
admin backup
- Create a manual backup of birthdays dataadmin restore latest
- Restore from the latest backupadmin cache clear
- Clear all web search cacheadmin cache clear DD/MM
- Clear web search cache for a specific date
The bot supports multiple personalities that change how birthday messages are written:
standard
- Friendly, enthusiastic birthday bot (default)mystic_dog
- Ludo the Mystic Birthday Dog who provides cosmic predictions and historical date factscustom
- Customizable personality using environment variables or commands
To change the personality:
- As an admin, use the command:
admin personality [name]
- The selection persists across bot restarts
Ludo's messages follow a specific structured format:
- A mystical greeting and request for celebratory GIFs
- Three insightful sections:
- Cosmic Analysis: Horoscope and numerological insights
- Spirit Guide: The person's spirit animal for the year
- Celestial Date Legacy: Scientific and historical facts about the birthday date, drawing from web searches
- A concluding message about the year ahead
The Celestial Date Legacy section incorporates web-searched information about notable scientific figures born on that date and significant historical events.
The bot maintains persistent configuration across restarts:
-
Admin Users: Admins are saved to
data/storage/admins.json
- Changes made with
admin add
andadmin remove
commands are persisted - Workspace admins always have admin privileges regardless of this list
- Changes made with
-
Bot Personality: Settings are saved to
data/storage/personality.json
- Active personality selection is remembered between restarts
- Custom personality settings are saved automatically
-
Custom Personality Configuration:
admin custom name [value]
- Set the bot's nameadmin custom description [value]
- Set the bot's character descriptionadmin custom style [value]
- Set the writing styleadmin custom format [value]
- Set formatting instructionsadmin custom template [value]
- Set additional template instructions
Edit the templates in config.py to customize:
BASE_TEMPLATE
- The core template all personalities shareBOT_PERSONALITIES
- Individual personality definitionstemplate_extension
- Personality-specific additions to the base template
Additional message components can be customized in utils/message_generator.py:
BACKUP_MESSAGES
- Fallback templates when AI is unavailableBIRTHDAY_INTROS
,BIRTHDAY_MIDDLES
, etc. - Components for template messages
Change when birthday checks run by modifying DAILY_CHECK_TIME
in config.py.
The bot implements several data management features:
- Automatic Backups: Creates timestamped backups of the birthdays file whenever it's modified
- Backup Rotation: Maintains the 10 most recent backups to save space
- Auto-Recovery: Tries to restore from backup if the main file is missing
- Web Search Caching: Stores retrieved historical date facts to reduce API calls
- Cached data is stored in
data/cache/
directory - Control caching with
WEB_SEARCH_CACHE_ENABLED
environment variable - Clear cache with
admin cache clear
or manually delete cache files
- Cached data is stored in
- Administrative Control: Provides commands for manual backup and restore operations
- Birthday Tracking: Prevents duplicate announcements if the bot is restarted
BrightDayBot includes a health check system to monitor the status of critical components:
- Storage Status: Checks if birthday data is accessible and reports the number of birthdays
- Admin Configuration: Verifies admin user configuration is properly loaded
- Web Search Cache: Monitors cache status, size, and most recent updates
- API Configuration: Validates that required API keys are configured
To check system health:
- As an admin, use the command:
admin status
- For detailed information including file paths and cache details:
admin status detailed
The health check helps diagnose issues quickly by showing the status of each component with visual indicators:
- ✅ Component is working correctly
- ℹ️ Component has a non-critical status
- ❌ Component has a critical issue that needs attention
If you encounter issues with BrightDayBot, follow these steps:
- Run the health check with
admin status
command in Slack - Check for any ❌ indicators in the status report
- For more detailed diagnostics, use
admin status detailed
- Verify all required environment variables are set correctly
- Ensure the bot has proper permissions in Slack
- Check that all required directories and files exist with proper permissions
- Review the log files in
data/logs/
for any error messages
Common issues:
- Missing API keys: Ensure
SLACK_BOT_TOKEN
,SLACK_APP_TOKEN
, andOPENAI_API_KEY
are set - Permission problems: Verify the bot has read/write permissions to the data directories
- Invalid configuration: Check that the
BIRTHDAY_CHANNEL
is set to a valid Slack channel ID
See LICENSE for details.