This documentation covers a Twitter bot system designed to automatically generate and manage crypto-related content, handle user interactions, and engage with relevant conversations on Twitter. The bot uses AI-powered content generation and maintains scheduled posting capabilities.
The central orchestrator that initializes and manages all bot components.
Key Features:
- Initializes the bot with personality configuration
- Manages scheduled operations
- Coordinates between different handlers
- Handles crypto content updates
- Runs periodic operational cycles
Configuration:
TWITTER_BEARER_TOKEN
TWITTER_API_KEY
TWITTER_API_SECRET
TWITTER_ACCESS_TOKEN
TWITTER_ACCESS_TOKEN_SECRET
OPENROUTER_API_KEY
COINGECKO_DEMO_API_KEY
EXA_API_KEY
NEWSDATA_API_KEYHandles the generation of various types of content using AI models.
Supported Models for post_model_name:
- microsoft/wizardlm-2-8x22b
- nousresearch/hermes-3-llama-3.1-405b
- mistralai/mistral-nemo
- meta-llama/llama-3.1-70b-instruct
Methods:
generate_post(): Creates new posts based on current events and contextgenerate_comment(): Generates comments for existing tweetsgenerate_response(): Creates responses to mentions_format_text(): Ensures content meets Twitter's character limits
Manages the collection and processing of crypto-related news and information.
Workflow Steps:
- Retrieves trending crypto information
- Fetches detailed coin information
- Obtains positive company information
- Schedules posts based on aggregated data
Manages the scheduling and timing of posts.
Features:
- Maintains pending and completed schedules
- Sorts schedules by time
- Handles schedule additions and removals
- Tracks overdue and future events
Handles responses to mentions and interactions.
Key Features:
- Processes mentions within a specified lookback period
- Generates contextual responses
- Maintains response history
- Filters mentions based on relevance
Manages the posting of scheduled content.
Features:
- Checks for due posts
- Generates and posts content
- Updates schedule status
- Handles posting errors
Proactively engages with relevant tweets based on configured buzzwords.
Features:
- Searches for relevant tweets
- Generates contextual responses
- Maintains engagement history
- Handles rate limits and errors
Purpose: Analyzes the context of replies and mentions
- Created via
create_reply_context_agent() - Uses model: "gpt-4o-mini"
- Provides contextual understanding for generating appropriate responses
Purpose: Composes reply content
- Created via
create_reply_composer_agent() - Uses configurable post model
- Generates contextually appropriate replies to mentions and interactions
Purpose: Analyzes the context of comments
- Created via
create_comment_context_agent() - Uses model: "gpt-4o-mini"
- Provides understanding for generating relevant comments
Purpose: Composes comment content
- Created via
create_comment_composer_agent() - Uses configurable post model
- Generates engaging comments on relevant posts
Purpose: Generates original posts
- Created via
create_post_generator_agent() - Uses configurable post model
- Creates original content based on current events and context
Purpose: Retrieves trending cryptocurrency information
- Created via
create_trending_crypto_agent() - Requires COINGECKO_DEMO_API_KEY
- Fetches current crypto market trends and data
Purpose: Provides detailed cryptocurrency information
- Created via
create_deep_coin_info_agent() - Requires EXA_API_KEY
- Retrieves in-depth analysis and information about specific cryptocurrencies
Purpose: Gathers company-related information
- Created via
create_company_info_agent() - Requires EXA_API_KEY and NEWSDATA_API_KEY
- Collects relevant company news and information
Purpose: Manages post scheduling
- Created via
create_schedule_agent() - Uses ScheduleTool for scheduling operations
- Handles timing and organization of scheduled posts
Purpose: Provides scheduling functionality
- Used by Schedule Agent
- Manages the actual scheduling operations
- Interfaces with ScheduleManager for schedule tracking
-
Environment Setup:
pip install -r requirements.txt
-
Configure Environment Variables: Create a
.envfile with the following: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_TOKEN_SECRET=your_access_token_secret OPENROUTER_API_KEY=your_openrouter_key COINGECKO_DEMO_API_KEY=your_coingecko_key EXA_API_KEY=your_exa_key NEWSDATA_API_KEY=your_newsdata_key
The system implements comprehensive error handling:
- API rate limit management
- Connection error recovery
- Content generation fallbacks
- Schedule management recovery
-
Logging:
- System uses Python's logging module
- Logs are formatted with timestamps and log levels
- Critical operations are logged for debugging
-
Performance Monitoring:
- Track API usage
- Monitor response times
- Track engagement metrics
-
Regular Maintenance:
- Update API keys as needed
- Monitor and update buzzwords
-
Planned Enhancements:
- Firebase integration for persistent storage
- Enhanced tweet relevance filtering
- Improved content generation algorithms
- Advanced scheduling capabilities
-
Potential Additions:
- Analytics dashboard
- Multi-account support
- Advanced sentiment analysis
- Enhanced error recovery mechanisms Here's the command to install your dependencies from your requirements.txt file:
pip install -r requirements.txtDon't remove the test.json file from your project directory—make sure it remains in place, as it’s needed for testing and configuration purposes.Also make sure that it's path is set properly in the .env file