An intelligent social media automation tool that generates, validates, and publishes engaging content to LinkedIn and Twitter using AI. Built with LangGraph for workflow orchestration and powered by Google's Gemini AI.
- AI-Powered Content Generation: Creates engaging LinkedIn posts and Twitter threads
- Smart Topic Generation: Generates diverse, thought-provoking tech topics
- Content Validation: Automatically validates posts against platform-specific rules
- Multi-Platform Publishing: Posts to both LinkedIn and Twitter simultaneously
- Community Support: Posts to Twitter communities with follower sharing
- Retry Logic: Automatically regenerates content if validation fails
- Interactive Topic Selection: Human approval for generated topics
- Framework: LangGraph for workflow orchestration
- AI Model: Google Gemini 2.0 Flash Lite
- Language: Python 3.13+
- APIs: LinkedIn API, Twitter API v2
- Authentication: OAuth 1.0 (Twitter), Bearer Token (LinkedIn)
Create a .env file in the root directory with the following variables:
# Google Gemini API
GEMINI_API_KEY=your_gemini_api_key_here
# Twitter API Credentials
twitter_consumer_key=your_twitter_consumer_key
twitter_consumer_secret=your_twitter_consumer_secret
twitter_access_token=your_twitter_access_token
twitter_access_token_secret=your_twitter_access_token_secret
twitter_community=your_twitter_community_id (optional)
# LinkedIn API Credentials
linkedin_access_token=your_linkedin_access_token
linkedin_unv=your_linkedin_user_id- Go to Google AI Studio
- Create a new API key
- Add it to your
.envfile asGEMINI_API_KEY
- Apply for Twitter Developer Account at developer.twitter.com
- Create a new App with Read and Write permissions
- Generate API Keys and Access Tokens
- Add all credentials to your
.envfile - (Optional) Get your community ID for community posting
- Create a LinkedIn App at LinkedIn Developers
- Request access to LinkedIn API
- Generate access token with
w_member_socialscope - Get your LinkedIn User ID (URN format)
- Add credentials to your
.envfile
-
Clone the repository
git clone <repository-url> cd ChatBot-LangGraph
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env with your API credentials
The bot follows a sophisticated workflow built with LangGraph that handles content generation, validation, and publishing across multiple platforms
-
Topic Generation
- AI generates unique, discussion-worthy tech topics
- Human reviews and approves/rejects topics
- Covers areas: Python, AI, Frontend, Backend, Automation, etc.
-
Content Creation (Parallel)
- LinkedIn: Professional, detailed posts with Unicode formatting
- Twitter: Concise, engaging tweets (โค260 characters)
-
Content Validation
- LinkedIn Validator: Checks formatting, length, completeness
- Twitter Validator: Verifies character limit, tone, engagement
-
Publishing
- LinkedIn: Posts to user's professional network
- Twitter: Posts to timeline and optionally to communities
- Fallback Logic: Attempts community + followers, falls back to community-only
-
Confirmation
- Reports success/failure status for both platforms
- Provides final confirmation message
# Activate virtual environment
source venv/bin/activate
# Run the bot
python main.py- Topic Selection: Review AI-generated topic and approve/reject
- Automatic Processing: Bot generates, validates, and posts content
- Results: See confirmation of successful posts
----------
Topic: The "Frontend Fatigue" Paradox: Is the constant churn in JavaScript frameworks actually slowing down development velocity?
Do You Want To Select This Topic (Yes/No): yes
----------Topic Selected----------
๐ Trying to post to community: 1493446837214187523 (with followers)
โ
Twitter Post created successfully!
โ
LinkedIn Post created successfully!
Both posts successfully published ๐
- Professional tone with engaging headlines
- Unicode bold formatting (๐ฏ๐ผ๐น๐ฑ ๐๐ฒ๐ ๐)
- Bullet points with "->" format
- โค600 tokens
- Discussion-worthy insights
- Concise and engaging (โค260 characters)
- Sarcastic, educational, or thought-provoking styles
- Bullet points with "->" format
- Relevant emojis only
- Max 1 hashtag
- Iteration Limits: Modify
total_linkedin_iterationsandtotal_twitter_iterations - Temperature: Adjust AI creativity in topic generation
- Specialties: Update the specialties list in
gen_topic() - Validation Rules: Modify validation criteria in respective functions
ChatBot-LangGraph/
โโโ main.py # Main workflow orchestration
โโโ linkedin.py # LinkedIn API integration
โโโ twitter.py # Twitter API integration
โโโ requirements.txt # Python dependencies
โโโ .env # Environment variables (create this)
โโโ .gitignore # Git ignore patterns
โโโ README.md # This file
-
403 Forbidden Errors
- Check API permissions and scopes
- Verify access tokens are valid
- Ensure app has read/write permissions
-
429 Rate Limit Errors
- Twitter API has posting limits (300 tweets per 15 minutes)
- Wait 15 minutes before trying again
- Consider upgrading to higher API tier for increased limits
-
Topic Repetition
- AI generates similar topics due to low temperature
- Restart the script for fresh context
-
Validation Failures
- Content doesn't meet platform guidelines
- Bot will retry up to 5 times per platform
-
Module Not Found
- Ensure virtual environment is activated
- Run
pip install -r requirements.txt
Enable detailed logging by uncommenting debug print statements in twitter.py and linkedin.py.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- Ensure compliance with platform terms of service
- Monitor API usage to avoid rate limits
- Review generated content before publishing
- Use responsibly and ethically
If you encounter issues:
- Check the troubleshooting section
- Verify your API credentials
- Review the logs for error messages
- Open an issue with detailed error information
Happy Posting! ๐
