An autonomous AI agent built in typescript that combines social media management with blockchain capabilities. Features Claude AI integration for intelligent interactions, Solana token creation/management, and automated Twitter engagement. Perfect for DeFi projects looking to automate community management and token operations.
BTB Finance Autonomous AI Agent ๐ค
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
Features
- ๐ฆ 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
Prerequisites
- Node.js v16 or higher
- npm or yarn
- Twitter Developer Account with API access
- OpenRouter API account
- Git
Setup Instructions
1. Clone the Repository
git clone https://github.com/btb-finance/autonomous-ai-agent.git
cd autonomous-ai-agent
2. Install Dependencies
npm install
3. Configure Twitter API
- 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:
4. Set Up OpenRouter
- Sign up at OpenRouter
- Generate an API key
- Choose your preferred AI model from available models
- Add credits if using premium models
5. Configure Environment Variables
Create a .env file in the project root:
# Twitter API OAuth 1.0a Credentials
TWITTERAPIKEY=yourapikey_here
TWITTERAPISECRET=yourapisecret_here
TWITTERACCESSTOKEN=youraccesstoken_here
TWITTERACCESSTOKENSECRET=youraccesstokensecret_here
TWITTERBEARERTOKEN=yourbearertoken_here
Twitter OAuth 2.0 Credentials (optional, for future features)
TWITTERCLIENTID=yourclientid_here
TWITTERCLIENTSECRET=yourclientsecret_here
OpenRouter API Configuration
OPENROUTERAPIKEY=youropenrouterapikeyhere
Choose any model from https://openrouter.ai/models
OPENROUTERMODEL=yourpreferredmodelhere
Ethereum Wallet Configuration (optional)
WALLETPRIVATEKEY=yourwalletprivatekeyhere
ETHRPCURL=yourethereumrpcurlhere
ETH_NETWORK=mainnet
6. Build the Project
npm run build
Running the Bot
Development Mode
npm run dev
Production Mode
npm run build
npm start
Available Commands
| 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 |
Testing Features
Test Tweet Posting
npm run test:tweet
This will post a test tweet from your configured account.
Test Mention Monitoring
npm run test:mentions
This will fetch the latest mentions of your account.
How It Works
- 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
Project Structure
โโโ 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
Twitter API Limits
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
Troubleshooting
Common Issues
- 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
Debug Mode
Enable detailed logging by setting the log level in your configuration:
monitoring: { logLevel: 'debug' }
Security Notes
- Never commit your
.envfile - Keep your API keys and tokens secure
- Regularly rotate your access tokens
- Use environment variables for all sensitive data
Contributing
- 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
Support
For issues and questions:
- Open an issue on GitHub
- Tweet at @btb_finance
- Check the documentation
License
This project is licensed under the MIT License - see the LICENSE file for details.