This project demonstrates how to build an intelligent Twitter bot that automatically finds and quote-tweets the best-performing content from a target account. The bot uses AI to generate engaging comments and tracks posted tweets to avoid duplicates.
It is designed for education and practical learning:
- Learn how to integrate AI models with social media APIs
- Understand OAuth 1.0a authentication for Twitter
- Apply scoring algorithms to select high-engagement content
- Implement stateful tracking with DynamoDB
- Use AWS Lambda for serverless automation
The setup is production-ready but also easy to customize and extend.
- AI-powered comments: Uses DeepSeek AI to generate witty, contextual responses
- Smart tweet selection: Scores tweets based on engagement metrics (likes, retweets, quotes, replies)
- Duplicate prevention: Tracks posted tweets in DynamoDB with automatic 90-day cleanup
- Fallback system: Uses predefined comments if AI generation fails
- Configurable target: Easily switch between different accounts to repost from
- Serverless architecture: Runs on AWS Lambda with scheduled triggers
The bot fetches the last 15 tweets from the target account and scores them using:
const score = m.like_count + 2 * m.retweet_count + 3 * m.quote_count + 0.5 * m.reply_count;This weighted scoring prioritizes viral content (especially quotes and retweets) while filtering out already-reposted tweets.
The selected tweet is sent to DeepSeek AI to generate a short, engaging comment (max 6 words). If AI generation fails, it falls back to predefined comments.
- AWS Lambda: Serverless execution with Node.js 22.x runtime
- DynamoDB: Stores posted tweet IDs with TTL for automatic cleanup
- Secrets Manager: Securely stores API credentials
- EventBridge: Schedules daily execution
- Node.js 18.x or higher
- AWS Account with CLI configured
- Twitter Developer Account with app credentials
- DeepSeek API key
1. Install dependencies:
npm install2. Change target account in index.js:
const sourceUsername = "elonmusk"; // Change to any Twitter username (without @)3. Set up AWS resources:
- Create DynamoDB table:
RepostedTweetswith partition keytweetId(String) - Enable TTL on attribute:
ttl - Store credentials in AWS Secrets Manager as
TwitterRepostSecrets
4. Deploy to Lambda:
See DEPLOYMENT.md for detailed AWS Lambda setup, testing, and scheduling instructions.
Create test-local.js with mocked AWS services to test logic before deployment:
const handler = require('./index').handler;
const AWS = require('aws-sdk');
const credentials = require('./credentials.json'); // Create this file with your keys
// Mock AWS services
AWS.SecretsManager = class {
getSecretValue() {
return { promise: () => Promise.resolve({ SecretString: JSON.stringify(credentials) }) };
}
};
AWS.DynamoDB.DocumentClient = class {
get() { return { promise: () => Promise.resolve({ Item: null }) }; }
put() { return { promise: () => Promise.resolve() }; }
};
// Run
handler().then(console.log).catch(console.error);Warning: This will actually post a tweet. Use with caution.
After deployment, use the Lambda console Test tab with empty JSON {} to manually trigger execution.
- Never commit credentials to version control
- Use AWS Secrets Manager for production credentials
- Use least-privilege IAM permissions
- Regularly rotate API keys
- Enable DynamoDB encryption at rest
Currently running on @devyoLife, demonstrating real-world automated content curation with AI-generated engagement.
For feedback, questions, or contributions, reach out here.
MIT License - Feel free to adapt for your own projects.