A NestJS-based AI bot that monitors Twitter, generates intelligent replies, and manages them through a Telegram approval workflow.
- Twitter Monitoring: Track tweets from specific users or hashtags
- AI-Powered Replies: Generate context-aware responses using OpenAI
- Telegram Approval: Review and manage replies through a Telegram bot
- Smart Filtering: Filter tweets based on engagement, keywords, and age
- Database Logging: Store all interactions in PostgreSQL using TypeORM
-
Clone the repository
git clone <repository-url> cd twitter-agent
-
Install dependencies
bun install
-
Set up environment variables
cp .env.example .env # Edit .env with your credentials -
Start the application
# Development bun run start:dev # Production bun run start:prod
Create a .env file with the following variables:
# Twitter API
TWITTER_BEARER_TOKEN=your_bearer_token
TWITTER_API_KEY=your_api_key
TWITTER_API_SECRET=your_api_secret
TWITTER_ACCESS_TOKEN=your_access_token
TWITTER_ACCESS_SECRET=your_access_secret
# OpenAI
OPENAI_API_KEY=your_openai_key
# Telegram
TELEGRAM_TOKEN=your_telegram_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/twitter_bot
# Application
PORT=3000
NODE_ENV=developmentConfigure tweet filtering in src/config/filter.config.ts:
export const filterConfig = {
engagement: {
minLikes: 10,
minRetweets: 5,
minReplies: 2
},
keywords: {
include: ['ai', 'technology'],
exclude: ['spam', 'ad']
},
age: {
maxHours: 24
}
};src/
├── content-approval/ # Telegram bot and approval workflow
├── content-generator/ # OpenAI integration and reply generation
├── db/ # Database entities and services
├── tasks/ # Scheduled tasks and cron jobs
├── twitter/ # Twitter API integration
└── config/ # Application configuration
-
Tweet Monitoring
- Bot monitors specified Twitter accounts/hashtags
- New tweets are filtered based on engagement and keywords
- Filtered tweets are stored in the database
-
Reply Generation
- OpenAI generates context-aware replies
- Replies are formatted and stored in the database
-
Approval Process
- Generated replies are sent to Telegram
- Approvers can:
- ✅ Approve the reply
- ❌ Reject the reply
- ✏️ Edit the reply text
-
Posting
- Approved replies are posted to Twitter
- All actions are logged in the database
- Node.js 18+ or Bun
- PostgreSQL 14+
- Twitter Developer Account
- OpenAI API Key
- Telegram Bot Token
# Install dependencies
bun install
# Run in development mode
bun run start:dev
# Run tests
bun run test
# Build for production
bun run build
# Start production server
bun run start:prodThis project is licensed under the MIT License - see the LICENSE file for details.
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
For support, please open an issue in the GitHub repository or contact the maintainers.