A robust Bluesky bot that posts daily David Hasselhoff content with improved stability, monitoring, and error handling. This code can be repurposed for any daily-posting image/text bot.
- Daily Posts: Automatically posts a Hoff quote and image at 10 AM daily
- Mention Monitoring: Likes posts that mention "David Hasselhoff", "The Hoff", or "Hasselhoff"
- Auto Follow-back: Automatically follows users who follow the bot
- Mention Responses: Likes posts that mention the bot directly
- Enhanced Stability: Comprehensive error handling and retry mechanisms
- Health Monitoring: Built-in health check endpoint for monitoring
- Process Monitoring: Automatic restart on crashes
- Rate Limiting: Prevents API abuse and rate limit violations
- Graceful Shutdown: Proper cleanup on termination signals
- Retry Logic: Automatic retries with exponential backoff for failed API calls
- Error Recovery: Comprehensive error handling that prevents crashes
- Rate Limiting: Built-in rate limiting to avoid API limits
- Health Monitoring: HTTP health check endpoint at
http://localhost:3001/health - Process Monitoring: Automatic restart on crashes with exponential backoff
- Enhanced Logging: Structured logging with different levels and timestamps
- Database Improvements: Better error handling and connection management
- Graceful Shutdown: Proper cleanup of resources on termination
- Node.js 18+
- SQLite3
- Bluesky account for the bot
git clone <repository-url>
cd bsky-hoffbot
npm installcp .env.example .envConfigure the following environment variables in .env:
BSKY_USERNAME- The username of the bot account (e.g., hoffbot.bsky.social)BSKY_PASSWORD- The password of the bot accountDATABASE_FILE- Name of the database file (e.g., hoffbot.db)FEED_URI- The URI of the custom feed that aggregates Hoff mentionsHOFFBOT_DID- The DID of the Hoffbot account (optional)
- Add Hoff images to
resources/hoffpics/ - Add quotes to
resources/quotes.txt(one quote per line)
npm run db:initDevelopment:
npm run startProduction with process monitoring:
npm run start:monitor| Script | Description |
|---|---|
npm run start |
Start the bot normally |
npm run start:monitor |
Start with process monitoring (recommended for production) |
npm run db:init |
Initialize the database |
npm run health |
Check bot health status |
npm run hoffbot:daily-hoff |
Run daily Hoff post manually |
npm run hoffbot:like-mentions |
Run mention checking manually |
npm run logs:clean |
Clean old log files (30+ days) |
npm run check:types |
Check TypeScript types |
npm run format |
Format code with Prettier |
The bot exposes a health check server on port 3001:
GET /health- Comprehensive health statusGET /ping- Simple ping/pong checkGET /metrics- System metrics (memory, uptime, etc.)
Example health check:
curl http://localhost:3001/health | jq# Copy the service file
sudo cp deployment/hoffbot.service /etc/systemd/system/
# Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable hoffbot
sudo systemctl start hoffbot
# Check status
sudo systemctl status hoffbotUse the provided deployment script:
chmod +x deployment/deploy.sh
sudo ./deployment/deploy.sh production- Daily Hoff Post: Every day at 10:00 AM
- Mention Checking: Every 3 hours
- Health Checks: Every 5 minutes
- Log Rotation: Automatic on restart
- Bot not starting: Check environment variables and network connectivity
- Database errors: Ensure write permissions to database file location
- Image/quote errors: Verify files exist in
resources/directory - API rate limits: Bot includes built-in rate limiting, but check Bluesky status
Set NODE_ENV=development for detailed debug logs.
# Real-time logs
tail -f logs/hoffbot.log
# Service logs (systemd)
journalctl -u hoffbot -f
# Health status
npm run health- Fork the repository
- Create a feature branch
- Make your changes with proper error handling
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.