### Environment Setup Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Sets up the environment variables required for testing the Twitter plugin. Ensure these are placed in a `.env.test` file in the plugin's root directory. ```bash TWITTER_API_KEY=your_api_key_here TWITTER_API_SECRET_KEY=your_api_secret_key_here TWITTER_ACCESS_TOKEN=your_access_token_here TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret_here ``` -------------------------------- ### Basic Twitter Plugin Configuration Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Example of how to include the Twitter plugin in your ElizaOS character configuration. This setup specifies the necessary plugins and provides examples for tweet generation. ```typescript const character = { // ... other config plugins: [ "@elizaos/plugin-bootstrap", // Required for content generation "@elizaos/plugin-twitter" // Twitter functionality ], postExamples: [ // Examples for tweet generation "Just discovered an amazing pattern in the data...", "The future of AI is collaborative intelligence", // ... more examples ] }; ``` -------------------------------- ### GitHub Actions CI/CD Integration Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Example configuration for a GitHub Actions workflow to run Twitter plugin tests, including setting up necessary environment secrets. ```yaml - name: Run Twitter Plugin Tests env: TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }} TWITTER_API_SECRET_KEY: ${{ secrets.TWITTER_API_SECRET_KEY }} TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} run: npm test ``` -------------------------------- ### Manual Tweet Operations Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Example TypeScript code demonstrating how to create, fetch, and like tweets using the `postService`. ```typescript // Test creating a tweet const post = await postService.createPost({ text: "Hello from ElizaOS!", agentId: "agent-123", roomId: "room-123", }); // Test fetching tweets const posts = await postService.getPosts({ agentId: "agent-123", limit: 20, }); // Test liking a tweet await postService.likePost("tweet-id", "agent-123"); ``` -------------------------------- ### Development and Testing Commands Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Provides commands for running tests, starting the bot with debug logging, and testing without posting. ```bash # Run tests bun test # Run with debug logging DEBUG=eliza:* bun start # Test without posting TWITTER_DRY_RUN=true bun start ``` -------------------------------- ### Performance Testing Commands Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Commands to run performance benchmarks and test rate limiting for the Twitter plugin. ```bash # Run performance benchmarks npm run benchmark # Test rate limiting npm run test:rate-limits ``` -------------------------------- ### Full Interaction Bot Setup Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Sets up the Twitter plugin for full interaction, enabling posting, replies, timeline actions (likes, retweets, quotes), and discovery features. ```env # Full interaction setup TWITTER_API_KEY=xxx TWITTER_API_SECRET_KEY=xxx TWITTER_ACCESS_TOKEN=xxx TWITTER_ACCESS_TOKEN_SECRET=xxx TWITTER_ENABLE_POST=true TWITTER_ENABLE_REPLIES=true TWITTER_ENABLE_ACTIONS=true # Enables likes, retweets, quotes TWITTER_ENABLE_DISCOVERY=true # Enables growth features ``` -------------------------------- ### Running Unit Tests Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Commands to execute unit tests using npm. Supports running all tests, specific files, with coverage, or in watch mode. ```bash # Run all unit tests npm test # Run specific test file npm test MessageService.test.ts # Run with coverage npm test -- --coverage # Run in watch mode npm test -- --watch ``` -------------------------------- ### ElizaOS Documentation Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Documentation for the ElizaOS platform, providing information on its architecture, core functionalities, and plugin development. ```APIDOC ElizaOS Documentation: Repository: https://github.com/elizaos/eliza Description: Official documentation for the ElizaOS operating system and its ecosystem. Relevant Sections for Plugins: - Plugin Architecture - API for interacting with ElizaOS core services - Data structures and communication protocols ``` -------------------------------- ### CI/CD GitHub Actions Setup Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/README.md Example GitHub Actions workflow for running Twitter plugin tests. It conditionally runs E2E tests based on the presence of API credentials stored as secrets. ```yaml - name: Run Unit Tests run: npm test unit - name: Run E2E Tests if: ${{ secrets.TWITTER_API_KEY != '' }} env: TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY }} TWITTER_API_SECRET_KEY: ${{ secrets.TWITTER_API_SECRET_KEY }} TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} run: npm test e2e ``` -------------------------------- ### Manual Direct Message Operations Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Example TypeScript code for fetching mentions and sending direct messages using the `messageService`. ```typescript // Test fetching mentions const mentions = await messageService.getMentions("agent-123", { limit: 10, }); // Test sending a DM const message = await messageService.sendMessage({ recipientId: "user-id", text: "Hello!", type: MessageType.DM, agentId: "agent-123", roomId: "room-123", }); ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Command to enable debug logging for ElizaOS-related modules during testing. ```bash DEBUG=elizaos:* npm test ``` -------------------------------- ### Minimal Twitter Setup Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Configures the Twitter plugin for basic posting functionality only. Ensures that only tweets are sent without any interactive features like replies or actions. ```env TWITTER_API_KEY=xxx TWITTER_API_SECRET_KEY=xxx TWITTER_ACCESS_TOKEN=xxx # Must have write permissions! TWITTER_ACCESS_TOKEN_SECRET=xxx TWITTER_ENABLE_POST=true TWITTER_POST_IMMEDIATELY=true # Great for testing TWITTER_ENABLE_REPLIES=false # Disable interactions TWITTER_ENABLE_ACTIONS=false # Disable timeline actions ``` -------------------------------- ### Running E2E Tests Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Commands to execute end-to-end tests, which require valid Twitter API credentials. Includes options to run or exclude E2E tests. ```bash # Run E2E tests (requires .env.test file) npm test -- --run e2e # Skip E2E tests if no credentials npm test -- --run --exclude="**/e2e/**" ``` -------------------------------- ### Character Configuration for Discovery Service Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Example JSON structure for an ElizaOS agent's character configuration, used by the Twitter Discovery Service to understand the agent's interests and topics. ```json { "name": "YourAgent", "topics": [ "artificial intelligence", "machine learning", "web3", "blockchain" ], "bio": "AI researcher interested in decentralized systems" } ``` -------------------------------- ### Twitter API v2 Documentation Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md Official documentation for the Twitter API v2, covering endpoints, authentication, and best practices for interacting with Twitter data. ```APIDOC Twitter API v2 Documentation: URL: https://developer.twitter.com/en/docs/twitter-api Description: Comprehensive guide to using the Twitter API v2 for developers. Key Areas: - Authentication (OAuth 2.0) - Endpoints for Tweets, Users, Spaces, etc. - Rate Limits and Best Practices - Request and Response Formats (JSON) ``` -------------------------------- ### Debugging Authentication Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md TypeScript code snippets to check the authentication status and fetch the user's profile using the Twitter client. ```typescript const isLoggedIn = await client.isLoggedIn(); console.log("Authenticated:", isLoggedIn); const profile = await client.me(); console.log("Profile:", profile); ``` -------------------------------- ### Node Twitter API v2 Library Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/TESTING_GUIDE.md A Node.js library for interacting with the Twitter API v2. It simplifies authentication and request handling. ```APIDOC node-twitter-api-v2 Library: Repository: https://github.com/PLhery/node-twitter-api-v2 Description: A JavaScript library for Node.js to interact with the Twitter API v2. Features: - Easy authentication (OAuth 1.0a, OAuth 2.0) - Methods for common API endpoints (tweets, users, etc.) - Request and response handling Usage Example (Conceptual): const { TwitterApi } = require('twitter-api-v2'); const twitterClient = new TwitterApi('YOUR_BEARER_TOKEN'); async function getTweets() { const tweets = await twitterClient.v2.get('tweets', { ids: '123,456' }); console.log(tweets); } ``` -------------------------------- ### E2E Test Environment Setup Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/README.md Configuration for end-to-end tests, specifying the required Twitter API v2 credentials in a `.env.test` file. It also includes a reminder to add this file to `.gitignore`. ```env # Twitter API v2 Credentials TWITTER_API_KEY=your_api_key_here TWITTER_API_SECRET_KEY=your_api_secret_key_here TWITTER_ACCESS_TOKEN=your_access_token_here TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret_here ``` -------------------------------- ### Discovery Service Configuration Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Configuration settings specifically for the Twitter Discovery Service. This includes enabling the service, setting discovery intervals, follower count thresholds, and limits for following and engagements. ```bash # Enable discovery service (defaults to true if TWITTER_ENABLE_ACTIONS=true) TWITTER_ENABLE_DISCOVERY=true # Discovery interval in minutes (default: 30) TWITTER_DISCOVERY_INTERVAL=30 # Minimum follower count for accounts to follow (default: 100) TWITTER_MIN_FOLLOWER_COUNT=100 # Maximum accounts to follow per cycle (default: 5) TWITTER_MAX_FOLLOWS_PER_CYCLE=5 # Maximum engagements per cycle (default: 10) TWITTER_MAX_ENGAGEMENTS_PER_RUN=10 ``` -------------------------------- ### Twitter/X Environment Variables Configuration Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Configuration of environment variables required for the Eliza Twitter/X Client. This includes OAuth 1.0a credentials, posting enablement, and posting intervals. ```bash # REQUIRED: OAuth 1.0a Credentials (from "Consumer Keys" section) TWITTER_API_KEY=your_api_key_here # From "API Key" TWITTER_API_SECRET_KEY=your_api_key_secret_here # From "API Key Secret" # REQUIRED: OAuth 1.0a Tokens (from "Authentication Tokens" section) TWITTER_ACCESS_TOKEN=your_access_token_here # Must have "Read and Write" TWITTER_ACCESS_TOKEN_SECRET=your_token_secret_here # Regenerate after permission change # Basic Configuration TWITTER_DRY_RUN=false # Set to true to test without posting TWITTER_ENABLE_POST=true # Enable autonomous tweet posting # Optional: Posting Configuration TWITTER_POST_IMMEDIATELY=true # Post on startup (great for testing) TWITTER_POST_INTERVAL=120 # Minutes between posts (default: 120) # For more natural timing, use MIN/MAX intervals: TWITTER_POST_INTERVAL_MIN=90 # Minimum minutes between posts TWITTER_POST_INTERVAL_MAX=150 # Maximum minutes between posts ``` -------------------------------- ### Twitter Plugin Configuration Reference Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md A comprehensive list of environment variables for configuring the Twitter plugin. This includes API credentials, feature toggles, timing intervals for various actions, and limits for engagement and tweet length. ```bash # Required Twitter API v2 Credentials (OAuth 1.0a) TWITTER_API_KEY= # Consumer API Key TWITTER_API_SECRET_KEY= # Consumer API Secret TWITTER_ACCESS_TOKEN= # Access Token (with write permissions) TWITTER_ACCESS_TOKEN_SECRET= # Access Token Secret # Core Configuration TWITTER_DRY_RUN=false # Set to true for testing without posting TWITTER_TARGET_USERS= # Comma-separated usernames to target (use "*" for all) TWITTER_RETRY_LIMIT=5 # Maximum retry attempts for failed operations # Feature Toggles TWITTER_ENABLE_POST=false # Enable autonomous tweet posting TWITTER_ENABLE_REPLIES=true # Enable mention and reply handling TWITTER_ENABLE_ACTIONS=false # Enable timeline actions (likes, retweets, quotes) TWITTER_ENABLE_DISCOVERY= # Enable discovery service (defaults to true if ACTIONS enabled) # Timing Configuration (all in minutes) # For natural behavior, set MIN/MAX intervals - the agent will randomly choose between them # If MIN/MAX not set, falls back to the fixed interval values # Post intervals TWITTER_POST_INTERVAL=120 # Fixed interval between posts (default: 120, used if MIN/MAX not set) TWITTER_POST_INTERVAL_MIN=90 # Minimum minutes between posts (default: 90) TWITTER_POST_INTERVAL_MAX=150 # Maximum minutes between posts (default: 150) # Engagement intervals TWITTER_ENGAGEMENT_INTERVAL=30 # Fixed interval for interactions (default: 30, used if MIN/MAX not set) TWITTER_ENGAGEMENT_INTERVAL_MIN=20 # Minimum minutes between engagements (default: 20) TWITTER_ENGAGEMENT_INTERVAL_MAX=40 # Maximum minutes between engagements (default: 40) # Discovery intervals TWITTER_DISCOVERY_INTERVAL_MIN=15 # Minimum minutes between discovery cycles (default: 15) TWITTER_DISCOVERY_INTERVAL_MAX=30 # Maximum minutes between discovery cycles (default: 30) # Engagement Limits TWITTER_MAX_ENGAGEMENTS_PER_RUN=5 # Maximum interactions per engagement cycle (default: 5) TWITTER_MAX_TWEET_LENGTH=280 # Maximum tweet length # Discovery Service Settings TWITTER_MIN_FOLLOWER_COUNT=100 # Minimum followers for accounts to follow TWITTER_MAX_FOLLOWS_PER_CYCLE=5 # Maximum accounts to follow per discovery cycle ``` -------------------------------- ### Running Unit Tests Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/README.md Commands to execute unit tests for the Twitter plugin. Includes options for running all tests, specific files, and with code coverage. ```bash # Run all unit tests npm test # Run specific test file npm test MessageService.test.ts # Run with coverage npm test -- --coverage ``` -------------------------------- ### Twitter API v2 Authentication and Permissions Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Details on obtaining Twitter Developer access, configuring app permissions for read/write, and acquiring the correct OAuth 1.0a credentials. ```APIDOC Twitter API v2 Setup: 1. Obtain Twitter Developer Account & Create App: - Visit https://developer.twitter.com - Create a new app in the Developer Portal. - Ensure the app has API v2 access. 2. Configure App Permissions: - Navigate to your app's settings in the Developer Portal. - Set 'App permissions' to 'Read and write'. - Set 'Type of App' to 'Web App, Automated App or Bot'. - Configure Required URLs: - Callback URI: http://localhost:3000/callback - Website URL: https://github.com/elizaos/eliza - Configure Optional Fields: - Organization name: ElizaOS - Organization URL: https://github.com/elizaos/eliza - Save changes. 3. Obtain OAuth 1.0a Credentials: - Go to your app's 'Keys and tokens' page. - USE THESE (OAuth 1.0a): - Consumer Keys: - API Key (maps to TWITTER_API_KEY) - API Key Secret (maps to TWITTER_API_SECRET_KEY) - Authentication Tokens: - Access Token (maps to TWITTER_ACCESS_TOKEN) - Access Token Secret (maps to TWITTER_ACCESS_TOKEN_SECRET) - IMPORTANT: After enabling write permissions, regenerate 'Access Token & Secret'. The new tokens will have write access. - DO NOT USE OAuth 2.0 Client ID, Client Secret, or Bearer Token for this integration. ``` -------------------------------- ### Target User Configuration Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Configures which users the Twitter bot will interact with. Can be set to interact with everyone, specific users, or no one. ```env # Interact with everyone (default) TWITTER_TARGET_USERS= # Interact with specific users only TWITTER_TARGET_USERS=user1,user2,user3 # Interact with everyone (explicit) TWITTER_TARGET_USERS=* ``` -------------------------------- ### Running End-to-End Tests Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/README.md Commands to execute end-to-end tests for the Twitter plugin. These tests require Twitter API credentials and can be run with verbose output. ```bash # Run E2E tests (will skip if no credentials) npm test e2e # Run with verbose output npm test e2e -- --reporter=verbose ``` -------------------------------- ### Testing Without Posting (Dry Run) Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/README.md Enables dry run mode for testing the Twitter plugin's functionality without actually posting or performing any actions on Twitter. Simulates all actions. ```env # Dry run mode TWITTER_DRY_RUN=true # Simulates all actions TWITTER_ENABLE_POST=true TWITTER_POST_IMMEDIATELY=true ``` -------------------------------- ### Debugging Tests Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/README.md Commands for debugging tests, including running in watch mode, enabling verbose output, and running specific tests by name. ```bash # Run tests in watch mode npm test -- --watch # Run with detailed error output npm test -- --reporter=verbose # Run specific test by name npm test -- -t "should create a simple post" ``` -------------------------------- ### Twitter Plugin Test Structure Source: https://github.com/elizaos-plugins/plugin-twitter/blob/1.x/src/__tests__/README.md Directory structure for the Twitter plugin tests, separating unit tests and end-to-end (e2e) tests. ```typescript __tests__/ ├── unit/ │ ├── MessageService.test.ts # Unit tests for TwitterMessageService │ ├── PostService.test.ts # Unit tests for TwitterPostService │ ├── auth.test.ts # Unit tests for TwitterAuth │ └── environment.test.ts # Unit tests for config validation └── e2e/ └── twitter-integration.test.ts # End-to-end tests with real API ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.