An intelligent Twitter bot that monitors mentions of $BTB, provides information about BTB Finance, and engages with the community using AI-powered responses.
Repository: https://github.com/btb-finance/Autonomous-AI-Agent
- 🐦 Twitter Integration: Monitors mentions, replies to tweets, and posts updates
- 🤖 AI-Powered Responses: Uses any AI model from OpenRouter (Claude, GPT-4, Gemini, etc.)
- 📚 Knowledge Base: Maintains information about BTB Finance for accurate responses
- 🔄 Real-time Processing: Continuously monitors Twitter for new mentions
- 💰 Wallet Integration: Ready for future cryptocurrency features
- 🛡️ Rate Limit Management: Handles Twitter API rate limits gracefully
- ⚡ TypeScript: Built with TypeScript for type safety and better developer experience
- Node.js v16 or higher
- npm or yarn
- Twitter Developer Account with API access
- OpenRouter API account
- Git
git clone https://github.com/btb-finance/autonomous-ai-agent.git
cd autonomous-ai-agent
npm install
- Go to Twitter Developer Portal
- Create a new app or use existing one
- Navigate to "User authentication settings"
- Ensure OAuth 1.0a is enabled with "Read and write" permissions
- Generate the following credentials:
- API Key and Secret
- Access Token and Secret
- Bearer Token
- Client ID and Secret (OAuth 2.0)
- Sign up at OpenRouter
- Generate an API key
- Choose your preferred AI model from available models
- Free options: deepseek/deepseek-r1-0528-qwen3-8b:free, nousresearch/hermes-3-llama-3.1-405b:free
- Premium options: anthropic/claude-3.5-sonnet, openai/gpt-4-turbo, google/gemini-pro
- Add credits if using premium models
Create a .env
file in the project root:
# Twitter API OAuth 1.0a Credentials
TWITTER_API_KEY=your_api_key_here
TWITTER_API_SECRET=your_api_secret_here
TWITTER_ACCESS_TOKEN=your_access_token_here
TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret_here
TWITTER_BEARER_TOKEN=your_bearer_token_here
# Twitter OAuth 2.0 Credentials (optional, for future features)
TWITTER_CLIENT_ID=your_client_id_here
TWITTER_CLIENT_SECRET=your_client_secret_here
# OpenRouter API Configuration
OPENROUTER_API_KEY=your_openrouter_api_key_here
# Choose any model from https://openrouter.ai/models
OPENROUTER_MODEL=your_preferred_model_here
# Ethereum Wallet Configuration (optional)
WALLET_PRIVATE_KEY=your_wallet_private_key_here
ETH_RPC_URL=your_ethereum_rpc_url_here
ETH_NETWORK=mainnet
npm run build
npm run dev
npm run build
npm start
Command | Description |
---|---|
npm run dev |
Run in development mode with hot reload |
npm start |
Run the production build |
npm run build |
Compile TypeScript to JavaScript |
npm test |
Run test suite |
npm run test:tweet |
Test tweet posting functionality |
npm run test:mentions |
Test mention fetching |
npm run lint |
Run ESLint |
npm run format |
Format code with Prettier |
npm run test:tweet
This will post a test tweet from your configured account.
npm run test:mentions
This will fetch the latest mentions of your account.
- Mention Monitoring: The bot checks for new mentions every 60 seconds
- $BTB Detection: Filters mentions containing "$BTB"
- Question Extraction: Extracts the actual question from the tweet
- Knowledge Base Search: Searches the local knowledge base for relevant information
- AI Response Generation: Uses your chosen OpenRouter model to generate an appropriate response
- Tweet Reply: Posts the response as a reply to the original tweet
├── src/
│ ├── services/ # Core service implementations
│ │ ├── TwitterService.ts # Twitter API integration
│ │ ├── OpenRouterService.ts # AI service integration
│ │ ├── BTBTweetService.ts # Main bot logic
│ │ ├── KnowledgeBaseService.ts # Knowledge management
│ │ └── WalletService.ts # Crypto wallet integration
│ ├── config/ # Configuration management
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ └── index.ts # Application entry point
├── knowledge_base/ # BTB Finance information
├── .env.example # Environment variables template
└── package.json # Project dependencies
Be aware of Twitter API rate limits:
- Free tier: 500 posts/month, limited read access
- Basic tier: 10,000 posts/month
- Pro tier: 1,000,000 posts/month
The bot includes automatic rate limit handling and will pause when limits are reached.
- 403 Forbidden Error: Your Twitter app needs "Read and write" permissions
- 401 Unauthorized: Check your API credentials are correct
- Rate Limit Errors: The bot will automatically wait and retry
- OpenRouter Errors: Ensure you have credits and valid API key
Enable detailed logging by setting the log level in your configuration:
monitoring: {
logLevel: 'debug'
}
- Never commit your
.env
file - Keep your API keys and tokens secure
- Regularly rotate your access tokens
- Use environment variables for all sensitive data
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature
- Commit changes:
git commit -am 'Add new feature'
- Push to branch:
git push origin feature/your-feature
- Submit a pull request
For issues and questions:
- Open an issue on GitHub
- Tweet at @btb_finance
- Check the documentation
This project is licensed under the MIT License - see the LICENSE file for details.