Twitter Posting Bot is an automated tweeting solution built with Streamlit and CrewAI. This application lets you schedule and publish tweets at regular intervals using either pre-written content from a text file or AI-generated tweets powered by OpenAI's GPT models. With customizable posting frequencies, AI prompting capabilities, and a user-friendly interface, it's the perfect tool for maintaining a consistent Twitter presence without manual intervention. Ideal for content creators, social media managers, and businesses looking to streamline their Twitter engagement strategy.
- Pre-written Tweets: Post tweets from a pre-defined text file
- AI-Generated Tweets: Generate tweets using CrewAI agents powered by OpenAI's GPT models
This application is perfect for social media managers, content creators, or anyone looking to maintain a consistent Twitter presence without manual intervention.
- 🕒 Scheduled Posting: Set custom time intervals for automated posting
- 🤖 AI Tweet Generation: Use OpenAI's GPT models to create engaging tweets
- ✏️ Collaborative AI Process: Two-agent system (writer + editor) for higher quality tweets
- 🔄 Tweet Preview: See upcoming tweets before they're posted
- 📝 Custom Prompts: Guide AI tweet generation with specific themes or topics
- 📊 Live Status Updates: Monitor bot activity with real-time status indicators
- 📜 Logging: Keep track of all bot activities with detailed logs
- 🌐 User-Friendly Interface: Easy-to-use Streamlit web interface
The application uses a combination of technologies:
- Streamlit: For the web interface
- Tweepy: For Twitter API interaction
- CrewAI: For agent-based AI tweet generation and refinement
- OpenAI GPT: For AI content generation
- Threading: For background task management
- Python 3.10+
- Twitter Developer Account with API credentials
- OpenAI API key
git clone https://github.com/Mr-PU/twitter-agent.git
cd twitter-agent# For Windows
python -m venv venv
venv\Scripts\activate
# For macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtIf the requirements.txt file is not included, create one with the following content:
streamlit
tweepy
crewai
openai
python-dotenv
copy .env.example .env
cp .env.example .env
Or, Create a .env file in the root directory with the following variables:
# Twitter API Credentials
API_KEY=your_twitter_api_key
API_SECRET=your_twitter_api_secret
ACCESS_TOKEN=your_twitter_access_token
ACCESS_TOKEN_SECRET=your_twitter_access_token_secret
# OpenAI API Key
OPENAI_API_KEY=your_openai_api_key
If you plan to use pre-written tweets, create a sample_tweets.txt file in the root directory with one tweet per line:
This is my first automated tweet! #TwitterBot
Excited to share more content with you all soon!
Check out my latest project: https://github.com/Mr-PU
streamlit run app.pyThis will start the Streamlit server and open the application in your default web browser.
-
Configure Settings:
- Set the posting interval in hours (minimum 0.01 hours ≈ 36 seconds)
- Choose between AI-generated or pre-written tweets
- If using AI, optionally provide a prompt to guide tweet generation
-
Start the Bot:
- Click the "Start" button to begin the automated posting process
- The bot will run in the background and post tweets at the specified interval
-
Monitor Activity:
- View the next tweet that will be posted
- See the status of recently posted tweets
- Check the agent status (Running/Stopped)
-
Stop the Bot:
- Click the "Stop" button to halt the posting process
The application maintains a detailed log file (twitter_agent.log) which can be viewed directly in the application by expanding the "View Logs" section at the bottom of the interface.
The application uses two CrewAI agents:
- Tweet Writer: Generates initial tweet drafts
- Tweet Editor: Refines and optimizes the drafts for clarity and engagement
You can modify the agent characteristics and prompts in the code to better suit your needs.
Be aware of Twitter API rate limits. The application is designed to post at reasonable intervals, but setting very short intervals might exceed your API quota, especially for free developer accounts.
-
Authentication Failed:
- Ensure your Twitter API credentials are correct
- Check that your Twitter Developer App has read/write permissions
-
OpenAI API Key Invalid:
- Verify your OpenAI API key is correct
- Check that your OpenAI account has sufficient credits
-
Tweet Posting Failed:
- Tweets exceeding 280 characters won't be posted
- Duplicate tweets might be rejected by Twitter
For detailed error information, check:
- The in-app log viewer
- The
twitter_agent.logfile in your project directory
[Include your license information here]
- Streamlit for the web interface framework
- Tweepy for Twitter API integration
- CrewAI for agent-based workflow
- OpenAI for AI language models
Contributions are welcome! Please feel free to submit a Pull Request.
.jpg?raw=true)