Twitter/X integration for Eliza Agents!
This library uses X API Access Keys instead of X username and password. We consider this to be more reliable, because your account won't get banned. Additionally, it's not a constant arms race to find new ways to outsmart the X dev team.
Use @elizaos-plugins/twitter-client if you are looking to use username and password authentication instead.
This is a work in progress and will be built out as needed.
- Post generation and management
- Interaction handling (mentions,
replies)(needs re-implementing) Search functionality(needs re-implementing)Twitter Spaces support with STT/TTS capabilities(needs re-implementing)Media handling (images, videos)(needs re-implementing)- Approval workflow via Discord (optional)
- A Twitter/X Developer Account with API access
- Node.js and pnpm installed
- Discord bot (if using approval workflow)
- ElevenLabs API key (if using Spaces with TTS)
- Sign into your X account.
- Go to https://developer.x.com/en/portal/petition/essential/basic-info and sign up for Developer Access. You can choose the Free Tier if you are just starting out.
- Go to https://developer.x.com/en/portal/projects-and-apps
- Find the Default Project that X created for you.
- Look for the App that X created for you and click the Settings gear.
- Scroll down to "User Authentication Settings" and click the "Set Up" button.
- Give the app "Read, Write, and Direct Message" permissions if you like.
- Under "Type of App" click "Web App, Automated App, or Bot".
- Under "App Info" -> "Callback URI" enter "http://localhost:5000"
- Under "App Info" -> "Website URL" enter your website URL.
- Scroll down and click "Save" to create your App. Confirm the popup dialog by pressing "Yes".
- Although we won't need them now, note down your app's "Client ID" and "Client Secret" in case you need them in the future. Press "Done" and "Yes I saved it".
- Go back to your App's Settings and click the "Keys and tokens" tab.
- Alternatively, go to https://developer.x.com/en/portal/projects/XXXXXX/apps/YYYYYY keys where XXXXX is your project ID and YYYYYY is your app ID.
- Look for "Consumer Keys" and click Regenerate. Important Write these down after you regenerate them.
- Look for "Authentication Tokens" then look for "Access Token and Secret". Click Regenerate, and it will create new tokens with Read, Write, and DM permissions. Important Write down the keys and values.
- Now you can use your API Key, API Secret, Access Token, and Access Secret to authenticate your user and use the API. We will do this in Step 3 below.
Install the plugin using eliza's command line tool. From your agent's root directory, do
npx elizaos plugins list
npx elizaos plugins add @elizaos-plugins/client-twitter-api-accessEdit your character json file and add @elizaos-plugins/client-twitter-api-access to your plugins.
Example
{
...
"plugins": [
...
"@elizaos-plugins/client-twitter-api-access"
],
...
}Create or edit .env file in your project root:
# Twitter API Credentials
TWITTER_APP_KEY= # API Key from the previous step
TWITTER_APP_SECRET= # API Secret from the previous step
TWITTER_ACCESS_TOKEN= # Access Token from the previous step
TWITTER_ACCESS_SECRET= # Access Secret from the previous step
# Twitter Client Configuration
TWITTER_DRY_RUN=false # Set to true for testing without posting
MAX_TWEET_LENGTH=280 # Default tweet length limit
TWITTER_SEARCH_ENABLE=false # Enable search functionality
TWITTER_RETRY_LIMIT=5 # Login retry attempts
TWITTER_POLL_INTERVAL=120 # Poll interval in seconds
TWITTER_TARGET_USERS= # Comma-separated list of target users
# Post Generation Settings
ENABLE_TWITTER_POST_GENERATION=true
POST_INTERVAL_MIN=90 # Minimum interval between posts (minutes)
POST_INTERVAL_MAX=180 # Maximum interval between posts (minutes)
POST_IMMEDIATELY=false # Skip approval workflow
# Interactions Settings
TWITTER_MENTIONS_LIMIT=10 # The number of most recent mentions to fetch and respond to
TWITTER_INTERACTIONS_CATCHUP=false # Set to True if you want the agent to add recent mentions to its database, without responding to them. This is useful if you have to delete your database for whatever reason
# Action Processing
ENABLE_ACTION_PROCESSING=false
ACTION_INTERVAL=5 # Action check interval (minutes)
MAX_ACTIONS_PROCESSING=1 # Maximum concurrent actions
# Spaces Configuration (Optional)
TWITTER_SPACES_ENABLE=false
ELEVENLABS_XI_API_KEY= # Required for TTS in Spaces
# Approval Workflow (Optional)
TWITTER_APPROVAL_DISCORD_BOT_TOKEN=
TWITTER_APPROVAL_DISCORD_CHANNEL_ID=
TWITTER_APPROVAL_CHECK_INTERVAL=300000 # 5 minutes in millisecondsThe client can automatically generate and post tweets based on your agent's character profile and topics. Posts can be:
- Regular tweets (≤280 characters)
- Long-form tweets (Note Tweets)(needs re-implementing)- Media tweets (with images/videos)(needs re-implementing)
Handles:
- Mentions
- Replies
- Quote tweets(need re-implementing)- Direct messages(needs re-implementing)
### Search (needs re-implementing)
When enabled, periodically searches Twitter for relevant topics and engages with found content.
### Twitter Spaces (needs re-implementing)
Supports creating and managing Twitter Spaces with:
- Speech-to-Text (STT) for transcription
- Text-to-Speech (TTS) via ElevenLabs
- Speaker management
- Idle monitoring
- Recording capabilities
Optional Discord-based approval system for tweets:
- Generated tweets are sent to a Discord channel
- Moderators can approve/reject via reactions
- Approved tweets are automatically posted
# Run tests
pnpm test
# Run with debug logging
DEBUG=eliza:* pnpm start- Verify character profile configuration
- Check MAX_TWEET_LENGTH setting
- Monitor approval workflow logs
- Never commit .env or credential files
- Use environment variables for sensitive data
- Implement proper rate limiting
- Monitor API usage and costs (especially for ElevenLabs)
For issues or questions:
- Check the Common Issues section
- Review debug logs (enable with DEBUG=eliza:*)
- Open an issue with:
- Error messages
- Configuration details
- Steps to reproduce