A Node.js Twitter bot that generates and automatically posts programmer thoughts, experiences, and insights using AI. The bot creates authentic, engaging tweets that mirror real programmer perspectives, ranging from technical tips to industry opinions and personal observations.
- 🎯 Generates authentic programmer-focused tweets
- ⏰ Automatic scheduling in IST timezone
- 🔄 Configurable content mix (technical, opinions, personal thoughts)
- 🎨 Natural language with proper context
- ⚡ Easy to customize and deploy
- Node.js (v14 or higher)
- A Twitter Developer Account with OAuth 2.0 credentials
- Google AI (Gemini) API key
- npm or yarn package manager
- Clone the repository:
git clone https://github.com/SalehKhatri/twitter_bot.git
cd twitter-bot- Install dependencies:
npm install- Create an environment file:
cp .env.example .env- Configure your environment variables in
.env:
TWITTER_API_KEY=your_api_key
TWITTER_API_SECRET=your_api_secret
TWITTER_ACCESS_TOKEN=your_access_token
TWITTER_ACCESS_SECRET=your_access_secret
GEMINI_API_KEY=your_gemini_api_keyThe tweet generation prompt can be customized in src/config/prompt.js. You can modify:
- Content mix ratio between technical and non-technical tweets
- Tone and style of tweets
- Specific topics to focus on
- Time scheduling preferences
Run the bot:
node bot.jsThe bot will:
- Generate tweets using the configured prompt
- Schedule them throughout the day (9 AM to 11:59 PM IST)
- Automatically post them at scheduled times
The bot generates three types of tweets:
-
Programming-related (50%):
- Coding experiences
- Technical insights
- Debugging stories
- Tool recommendations
-
Tech Culture & Opinions (30%):
- Industry observations
- Hot takes on trends
- Work-life balance
- Tech workplace culture
-
Personal & Random (20%):
- Programmer lifestyle
- Coffee addiction
- Setup struggles
- Weekend coding plans
Common issues and solutions:
-
Timezone Issues:
- Ensure your server's timezone is properly set
- Check that all generated timestamps are in IST
- Verify the cron job timezone settings
-
API Rate Limits:
- Twitter has rate limits for posting
- Ensure tweets are spaced appropriately
- Monitor your API usage
-
Content Generation:
- Adjust the prompt if tweets are too repetitive
- Fine-tune the content mix ratios
- Modify example tweets for better variety
MIT License - feel free to use this for your own Twitter bot!
Contributions are welcome! Please feel free to submit a Pull Request.
- Thanks to Google's Gemini AI for powering the tweet generation
- Twitter API for enabling automated posting
- The developer community for inspiration
- Keep your API keys secure and never commit them to the repository
- Follow Twitter's automation rules and best practices
- Monitor your bot's output to ensure quality content
- Regularly update dependencies for security
If you have any questions or suggestions, please open an issue or reach out to [your contact information].
Remember to 🌟 star this repository if you find it helpful!