Skip to content

3thousand30/simple_twitter_repost_ai_agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Twitter Repost Agent (Educational Project)

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.

🔑 Key Features

  • 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

🧠 How It Works

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 Architecture

  • 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

🔧 Quick Start

Prerequisites

  • Node.js 18.x or higher
  • AWS Account with CLI configured
  • Twitter Developer Account with app credentials
  • DeepSeek API key

Configuration

1. Install dependencies:

npm install

2. Change target account in index.js:

const sourceUsername = "elonmusk"; // Change to any Twitter username (without @)

3. Set up AWS resources:

  • Create DynamoDB table: RepostedTweets with partition key tweetId (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.

🧪 Testing

Local Testing (Without AWS)

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.

Testing in Lambda

After deployment, use the Lambda console Test tab with empty JSON {} to manually trigger execution.

🔐 Security Best Practices

  • 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

🌟 Live Example

Currently running on @devyoLife, demonstrating real-world automated content curation with AI-generated engagement.

💬 Contact & Contributions

For feedback, questions, or contributions, reach out here.

📝 License

MIT License - Feel free to adapt for your own projects.

About

A simple Twitter (currently called X) reposting AI agent that works and is highly customizable.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors