This NestJS-powered bot scans Nostr for posts containing x.com/twitter.com and reddit.com links and automatically replies with privacy-respecting alternative front-end mirrors.
- Twitter/X and Reddit embed trackers, cookies, and surveillance bloat
- Alternative front-ends like Nitter and Redlib are lightweight, open-source alternatives that strip out tracking
- Browse social media content without feeding engagement algorithms or compromising your privacy
- Supports multiple mirror instances for better reliability and availability
Twitter/X Alternative Front-ends:
- XCancel (https://xcancel.com)
- Poast Nitter (https://nitter.poast.org)
- Nitter.net (https://nitter.net)
Reddit Alternative Front-ends:
- Troddit (https://www.troddit.com)
- Redlib PrivacyRedirect (Finland) (https://redlib.privacyredirect.com)
- Redlib CatsArch (US) (https://redlib.catsarch.com)
- Real-time Monitoring: Listens to Nostr network for new text notes (kind 1 events)
- Link Detection: Scans posts for Twitter/X and Reddit URLs using regex patterns
- URL Cleaning: Strips tracking parameters and query strings from detected URLs
- Alternative Generation: Creates corresponding URLs for multiple alternative front-ends
- Smart Replies: Posts formatted replies with all available alternative links
- Cache Management: Prevents duplicate replies using time-based caching
- Debug Mode: Optional logging-only mode for testing without publishing
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- npm (comes with Node.js)
- Git (for cloning the repository)
This is a NestJS framework TypeScript bot.
git clone https://github.com/0x80085/nostr-nitter-replybot.git
cd nostr-nitter-replybot
npm installGenerate a public/private key pair for your Nostr bot account:
npm run keygen.env file. Keep your private key secure and never commit it to version control.
Create a .env file in the root directory with the following configuration:
# Environment (use 'production' when deployed to a live server)
NODE_ENV=development
# Database configuration (for future use with Prisma)
DATABASE_URL="file:./dev.db"
# Nostr Bot Keys (Generated from step 2)
NOSTR_BOT_PRIVATE_KEY="<HEX PRIVATE KEY HERE>"
NOSTR_BOT_PUBLIC_KEY="<HEX PUBLIC KEY HERE>"
# API Security (Generate a random string to protect your endpoints)
AUTH_APP_TOKEN="<GENERATE_RANDOM_TOKEN>"
# Debug mode - set to false in production
IS_DEBUG_MODE=true
# Optional NIP05 verification settings
NIP05_VERIFICATION_DOMAIN_URL="https://example.com/.well-known/nostr.json"
NIP05_VERIFICATION_DOMAIN_EMAIL="[email protected]"
# Cache and connection settings
CACHE_TTL_MINUTES=30
RECONNECTION_DELAY_SECONDS=60
# Nostr relay configuration
NOSTR_RELAYS="wss://relay.damus.io,wss://nostr.mom,wss://relay.nostr.band"
# Ignored Author's npub in HEX version
IGNORED_AUTHORS="c558c7cc69bbda3c271782b736babc64acd2da258b14f356dbca966cb0b7b89e"
# Server configuration
PORT=3000
# Logging settings
LOG_RETENTION_DAYS="30d"
LOG_DIRECTORY="logs"🔐 Security Important:
- Never commit your
.envfile to version control - Use a strong, random
AUTH_APP_TOKEN - Keep your private key confidential
# Development mode with auto-reload
npm run start:dev
# Production mode
npm run start:prod
# Basic start
npm startWhen the bot detects Twitter/X or Reddit links in a Nostr post, it replies with a formatted message containing alternative front-end links:
🔗 Twitter/X Alternative Links:
XCancel: https://xcancel.com/user/status/123456789
Poast Nitter: https://nitter.poast.org/user/status/123456789
Nitter: https://nitter.net/user/status/123456789
🔗 Reddit Alternative Links:
Troddit: https://www.troddit.com/r/example/comments/abc123
Redlib (Finland): https://redlib.privacyredirect.com/r/example/comments/abc123
Redlib (US): https://redlib.catsarch.com/r/example/comments/abc123
The project includes additional utility scripts:
# Transform existing keys between formats
npm run transform# Development with auto-reload
npm run start:dev
# Debug mode with inspector
npm run start:debug
# Build for production
npm run build
# Production mode
npm run start:prod
# Format code
npm run format
# Lint code
npm run lintThe project includes comprehensive testing capabilities:
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage report
npm run test:cov
# Run end-to-end tests
npm run test:e2e
# Debug tests
npm run test:debugCoverage reports are generated in the coverage/ directory.
The bot exposes a REST API on port 3000 (configurable via PORT environment variable):
- GET /: Health check endpoint
- GET /stats: Statistics dashboard showing bot performance metrics
- Swagger Documentation: Available at
http://localhost:3000/apiwhen running
The API is protected by the AUTH_APP_TOKEN for security (except for the stats dashboard which is publicly accessible).
- Log Files: Stored in the
logs/directory - Log Rotation: Configured for daily rotation with retention period set by
LOG_RETENTION_DAYS - Debug Mode: When
IS_DEBUG_MODE=true, replies are logged instead of posted to Nostr - Statistics Dashboard: Monitoring dashboard available at
http://localhost:3000/stats(refresh page for updated metrics) showing:- Daily reply count
- Cache statistics (entries and memory usage)
- Relay connection status
- Bot configuration details
- Next cache cleanup time
To verify your bot is working correctly:
- Check Logs: Monitor the log files for connection status and activity
- Test Mode: Run with
IS_DEBUG_MODE=trueto see what replies would be generated - Health Check: Visit
http://localhost:3000for a basic health check - Network Status: Check relay connections in the logs
Bot not connecting to relays:
- Check your internet connection
- Verify relay URLs in
NOSTR_RELAYSare correct and responsive - Check firewall settings for WebSocket connections
No replies being generated:
- Ensure
IS_DEBUG_MODEis set tofalsefor live posting - Verify your user's public key is not in the
IGNORED_AUTHORSlist - Check that your private key is valid
To test the bot without posting to Nostr:
- Set
IS_DEBUG_MODE=truein your.envfile - Start the bot with
npm run start:dev - Monitor logs to see detected links and generated replies
- When ready for live operation, set
IS_DEBUG_MODE=falseand NODE_ENV toproduction
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the deployment documentation for more information.
Check out a few resources that may come in handy when working with this project:
- Visit the NestJS Documentation to learn more about the framework.
- To dive deeper and get more hands-on experience, check out our official video courses.
- Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
- rx-nostr which powers this project. View on Github
- Nostr NIPs
This Nostr bot is MIT licensed.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please open an issue on the GitHub repository.
