Skip to main content

Overview

The @elizaos/plugin-twitter package provides comprehensive Twitter/X API v2 integration for elizaOS agents. It enables agents to operate as fully autonomous Twitter bots with capabilities including tweet posting, timeline monitoring, interaction handling, direct messaging, and advanced features like weighted timeline algorithms. This plugin handles all Twitter-specific functionality including:
  • Managing Twitter API authentication and client connections
  • Autonomous tweet generation and posting
  • Timeline monitoring and interaction processing
  • Search functionality and mention tracking
  • Direct message handling
  • Advanced timeline algorithms with configurable weights
  • Rate limiting and request queuing
  • Media attachment support

Architecture Overview

Core Components

Twitter Service

The TwitterService class manages multiple Twitter client instances:

Client Base

The foundation for all Twitter operations:

Post Client

Handles autonomous tweet posting:

Interaction Client

Manages timeline monitoring and interactions:

Timeline Client

Advanced timeline processing with actions:

Authentication & Setup

Developer Account Setup

  1. Apply for Developer Account
  2. Create App
  3. Configure Permissions

OAuth Setup

Critical: Use OAuth 1.0a, NOT OAuth 2.0!

Token Regeneration

After changing permissions:
  1. Go to “Keys and tokens”
  2. Under “Authentication Tokens”
  3. Click “Regenerate” for Access Token & Secret
  4. Copy new tokens
  5. Update .env file

Configuration

Environment Variables

Character Configuration

Timeline Algorithms

Weighted Algorithm

Sophisticated scoring system for quality interactions:

Latest Algorithm

Simple chronological processing:

Message Processing

Tweet Generation

Response Generation

Rate Limiting & Queuing

Request Queue Implementation

Rate Limiter

Error Handling

API Error Handling

Retry Logic

Integration Guide

Basic Setup

Multi-Account Setup

Custom Actions

Performance Optimization

Caching Strategy

Batch Operations

Memory Management

Best Practices

  1. Authentication
    • Always use OAuth 1.0a for user context
    • Store credentials securely
    • Regenerate tokens after permission changes
  2. Rate Limiting
    • Implement proper backoff strategies
    • Cache frequently accessed data
    • Use batch endpoints when possible
  3. Content Generation
    • Provide diverse postExamples
    • Vary posting times with variance
    • Monitor engagement metrics
  4. Error Handling
    • Log all errors with context
    • Implement graceful degradation
    • Notify on critical failures
  5. Performance
    • Use appropriate timeline algorithms
    • Implement efficient caching
    • Monitor memory usage

Support

For issues and questions: