@elizaos/plugin-twitter 1.0.13 โ†’ 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,36 +1,166 @@
1
1
  # Eliza Twitter/X Client
2
2
 
3
- This package provides Twitter/X integration for the Eliza AI agent using Twitter API v2.
3
+ This package provides Twitter/X integration for the Eliza AI agent using the official Twitter API v2.
4
+
5
+ ## ๐Ÿšจ TL;DR - Quick Setup
6
+
7
+ **Just want your bot to post tweets? Here's the fastest path:**
8
+
9
+ 1. **Get Twitter Developer account** โ†’ https://developer.twitter.com
10
+ 2. **Create an app** โ†’ Enable "Read and write" permissions
11
+ 3. **Get OAuth 1.0a credentials** (NOT OAuth 2.0!):
12
+ - API Key & Secret (from "Consumer Keys")
13
+ - Access Token & Secret (from "Authentication Tokens")
14
+ 4. **Add to `.env`:**
15
+ ```bash
16
+ TWITTER_API_KEY=xxx
17
+ TWITTER_API_SECRET_KEY=xxx
18
+ TWITTER_ACCESS_TOKEN=xxx
19
+ TWITTER_ACCESS_TOKEN_SECRET=xxx
20
+ TWITTER_POST_ENABLE=true
21
+ TWITTER_POST_IMMEDIATELY=true
22
+ ```
23
+ 5. **Run:** `bun start`
24
+
25
+ โš ๏ธ **Common mistake:** Using OAuth 2.0 credentials instead of OAuth 1.0a - see [Step 3](#step-3-get-the-right-credentials-oauth-10a) for details!
4
26
 
5
27
  ## Features
6
28
 
7
- - Autonomous tweet posting with configurable intervals
8
- - Timeline monitoring and interaction
9
- - Mention and reply handling
10
- - Search functionality
11
- - Direct message support
12
- - Advanced timeline algorithms with weighted scoring
13
- - Action processing and automated responses
14
- - Comprehensive caching system
29
+ - โœ… **Autonomous tweet posting** with configurable intervals
30
+ - โœ… **Timeline monitoring** and interaction
31
+ - โœ… **Mention and reply handling**
32
+ - โœ… **Search functionality**
33
+ - โœ… **Direct message support**
34
+ - โœ… **Advanced timeline algorithms** with weighted scoring
35
+ - โœ… **Comprehensive caching system**
36
+ - โœ… **Built-in rate limiting and retry mechanisms**
15
37
 
16
- ## Setup Guide
17
-
18
- ### Prerequisites
38
+ ## Prerequisites
19
39
 
20
40
  - Twitter Developer Account with API v2 access
21
- - Twitter API v2 credentials (API Key, API Secret, Access Token, Access Token Secret)
41
+ - Twitter OAuth 1.0a credentials (NOT OAuth 2.0)
22
42
  - Node.js and bun installed
23
43
 
24
- ### Step 1: Configure Environment Variables
44
+ ## ๐Ÿš€ Quick Start
45
+
46
+ ### Step 1: Get Twitter Developer Access
47
+
48
+ 1. Apply for a developer account at https://developer.twitter.com
49
+ 2. Create a new app in the [Developer Portal](https://developer.twitter.com/en/portal/projects-and-apps)
50
+ 3. Ensure your app has API v2 access
51
+
52
+ ### Step 2: Configure App Permissions for Posting
53
+
54
+ **โš ๏ธ CRITICAL: Default apps can only READ. You must enable WRITE permissions to post tweets!**
55
+
56
+ 1. In your app settings, go to **"User authentication settings"**
57
+ 2. Configure exactly as shown:
58
+
59
+ **App permissions**: `Read and write` โœ…
60
+
61
+ **Type of App**: `Web App, Automated App or Bot`
62
+
63
+ **Required URLs** (copy these exactly):
64
+ ```
65
+ Callback URI: http://localhost:3000/callback
66
+ Website URL: https://github.com/elizaos/eliza
67
+ ```
68
+
69
+ **Optional fields**:
70
+ ```
71
+ Organization name: ElizaOS
72
+ Organization URL: https://github.com/elizaos/eliza
73
+ ```
74
+
75
+ 3. Click **Save**
76
+
77
+ ### Step 3: Get the RIGHT Credentials (OAuth 1.0a)
78
+
79
+ **โš ๏ธ IMPORTANT: You need OAuth 1.0a credentials, NOT OAuth 2.0!**
80
+
81
+ In your app's **"Keys and tokens"** page, you'll see several sections. Here's what to use:
82
+
83
+ ```
84
+ โœ… USE THESE (OAuth 1.0a):
85
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
86
+ โ”‚ Consumer Keys โ”‚
87
+ โ”‚ โ”œโ”€ API Key: xxx...xxx โ†’ TWITTER_API_KEY โ”‚
88
+ โ”‚ โ””โ”€ API Key Secret: xxx...xxx โ†’ TWITTER_API_SECRET_KEY โ”‚
89
+ โ”‚ โ”‚
90
+ โ”‚ Authentication Tokens โ”‚
91
+ โ”‚ โ”œโ”€ Access Token: xxx...xxx โ†’ TWITTER_ACCESS_TOKEN โ”‚
92
+ โ”‚ โ””โ”€ Access Token Secret: xxx โ†’ TWITTER_ACCESS_TOKEN_SECRET โ”‚
93
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
94
+
95
+ โŒ DO NOT USE THESE (OAuth 2.0):
96
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
97
+ โ”‚ OAuth 2.0 Client ID and Client Secret โ”‚
98
+ โ”‚ โ”œโ”€ Client ID: xxx...xxx โ† IGNORE โ”‚
99
+ โ”‚ โ””โ”€ Client Secret: xxx...xxx โ† IGNORE โ”‚
100
+ โ”‚ โ”‚
101
+ โ”‚ Bearer Token โ† IGNORE โ”‚
102
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
103
+ ```
104
+
105
+ **After enabling write permissions, you MUST:**
106
+ 1. Click **"Regenerate"** on Access Token & Secret
107
+ 2. Copy the NEW tokens (old ones won't have write access)
108
+ 3. Look for "Created with Read and Write permissions" โœ…
109
+
110
+ ### Step 4: Configure Environment Variables
25
111
 
26
112
  Create or edit `.env` file in your project root:
27
113
 
28
114
  ```bash
29
- # Required Twitter API v2 Credentials
30
- TWITTER_API_KEY= # Your Twitter API Key
31
- TWITTER_API_SECRET_KEY= # Your Twitter API Secret Key
32
- TWITTER_ACCESS_TOKEN= # Your Access Token
33
- TWITTER_ACCESS_TOKEN_SECRET= # Your Access Token Secret
115
+ # REQUIRED: OAuth 1.0a Credentials (from "Consumer Keys" section)
116
+ TWITTER_API_KEY=your_api_key_here # From "API Key"
117
+ TWITTER_API_SECRET_KEY=your_api_key_secret_here # From "API Key Secret"
118
+
119
+ # REQUIRED: OAuth 1.0a Tokens (from "Authentication Tokens" section)
120
+ TWITTER_ACCESS_TOKEN=your_access_token_here # Must have "Read and Write"
121
+ TWITTER_ACCESS_TOKEN_SECRET=your_token_secret_here # Regenerate after permission change
122
+
123
+ # Basic Configuration
124
+ TWITTER_DRY_RUN=false # Set to true to test without posting
125
+ TWITTER_POST_ENABLE=true # Set to true to enable auto-posting
126
+
127
+ # Optional: Posting Configuration
128
+ TWITTER_POST_IMMEDIATELY=true # Post on startup (great for testing)
129
+ TWITTER_POST_INTERVAL_MIN=90 # Minimum minutes between posts
130
+ TWITTER_POST_INTERVAL_MAX=180 # Maximum minutes between posts
131
+ ```
132
+
133
+ ### Step 5: Run Your Bot
134
+
135
+ ```typescript
136
+ // Your character should include the twitter plugin
137
+ const character = {
138
+ // ... other config
139
+ plugins: [
140
+ "@elizaos/plugin-bootstrap", // Required for content generation
141
+ "@elizaos/plugin-twitter" // Twitter functionality
142
+ ],
143
+ postExamples: [ // Examples for tweet generation
144
+ "Just discovered an amazing pattern in the data...",
145
+ "The future of AI is collaborative intelligence",
146
+ // ... more examples
147
+ ]
148
+ };
149
+ ```
150
+
151
+ Then start your bot:
152
+ ```bash
153
+ bun run start
154
+ ```
155
+
156
+ ## ๐Ÿ“‹ Complete Configuration Reference
157
+
158
+ ```bash
159
+ # Required Twitter API v2 Credentials (OAuth 1.0a)
160
+ TWITTER_API_KEY= # Consumer API Key
161
+ TWITTER_API_SECRET_KEY= # Consumer API Secret
162
+ TWITTER_ACCESS_TOKEN= # Access Token (with write permissions)
163
+ TWITTER_ACCESS_TOKEN_SECRET= # Access Token Secret
34
164
 
35
165
  # Basic Configuration
36
166
  TWITTER_DRY_RUN=false # Set to true for testing without posting
@@ -42,7 +172,7 @@ TWITTER_POLL_INTERVAL=120 # Timeline polling interval (seconds)
42
172
  TWITTER_POST_ENABLE=false # Enable autonomous tweet posting
43
173
  TWITTER_POST_INTERVAL_MIN=90 # Minimum interval between posts (minutes)
44
174
  TWITTER_POST_INTERVAL_MAX=180 # Maximum interval between posts (minutes)
45
- TWITTER_POST_IMMEDIATELY=false # Skip intervals and post immediately
175
+ TWITTER_POST_IMMEDIATELY=false # Post immediately on startup
46
176
  TWITTER_POST_INTERVAL_VARIANCE=0.2 # Random variance factor for posting intervals
47
177
 
48
178
  # Interaction Settings
@@ -67,81 +197,98 @@ TWITTER_ENABLE_ACTION_PROCESSING=false # Enable timeline action processing
67
197
  TWITTER_ACTION_INTERVAL=240 # Action processing interval (minutes)
68
198
  ```
69
199
 
70
- ### Step 2: Initialize the Client
200
+ ## ๐ŸŽฏ Common Use Cases
71
201
 
72
- ```typescript
73
- import { TwitterClientInterface } from "@elizaos/plugin-twitter";
202
+ ### Just Want to Post Tweets?
74
203
 
75
- const twitterPlugin = {
76
- name: "twitter",
77
- description: "Twitter client",
78
- services: [TwitterService],
79
- };
204
+ ```bash
205
+ # Minimal setup for posting only
206
+ TWITTER_API_KEY=xxx
207
+ TWITTER_API_SECRET_KEY=xxx
208
+ TWITTER_ACCESS_TOKEN=xxx # Must have write permissions!
209
+ TWITTER_ACCESS_TOKEN_SECRET=xxx
210
+
211
+ TWITTER_POST_ENABLE=true
212
+ TWITTER_POST_IMMEDIATELY=true # Great for testing
213
+ TWITTER_SEARCH_ENABLE=false # Disable interactions
214
+ ```
215
+
216
+ ### Want Full Interaction Bot?
80
217
 
81
- // Register with your Eliza runtime
82
- runtime.registerPlugin(twitterPlugin);
218
+ ```bash
219
+ # Full interaction setup
220
+ TWITTER_API_KEY=xxx
221
+ TWITTER_API_SECRET_KEY=xxx
222
+ TWITTER_ACCESS_TOKEN=xxx
223
+ TWITTER_ACCESS_TOKEN_SECRET=xxx
224
+
225
+ TWITTER_POST_ENABLE=true
226
+ TWITTER_SEARCH_ENABLE=true
227
+ TWITTER_AUTO_RESPOND_MENTIONS=true
228
+ TWITTER_AUTO_RESPOND_REPLIES=true
83
229
  ```
84
230
 
85
- ## Authentication
231
+ ### Testing Without Posting?
86
232
 
87
- This plugin uses **Twitter API v2** with OAuth 1.0a authentication. You need:
233
+ ```bash
234
+ # Dry run mode
235
+ TWITTER_DRY_RUN=true # Simulates all actions
236
+ TWITTER_POST_ENABLE=true
237
+ TWITTER_POST_IMMEDIATELY=true
238
+ ```
88
239
 
89
- 1. **Twitter Developer Account**: Apply at https://developer.twitter.com
90
- 2. **API v2 Access**: Ensure your app has API v2 access enabled
91
- 3. **Credentials**: Generate API Key, API Secret, Access Token, and Access Token Secret
240
+ ## ๐Ÿ”ง Troubleshooting
92
241
 
93
- ### Getting Twitter API Credentials
242
+ ### "403 Forbidden" When Posting
94
243
 
95
- 1. Go to https://developer.twitter.com/en/portal/dashboard
96
- 2. Create a new app or use an existing one
97
- 3. Navigate to "Keys and tokens"
98
- 4. Generate/copy:
99
- - API Key (`TWITTER_API_KEY`)
100
- - API Secret Key (`TWITTER_API_SECRET_KEY`)
101
- - Access Token (`TWITTER_ACCESS_TOKEN`)
102
- - Access Token Secret (`TWITTER_ACCESS_TOKEN_SECRET`)
244
+ This is the #1 issue! Your app has read-only permissions.
103
245
 
104
- ## Features
246
+ **Solution:**
247
+ 1. Go to app settings โ†’ "User authentication settings"
248
+ 2. Change to "Read and write"
249
+ 3. Save settings
250
+ 4. **CRITICAL**: Regenerate your Access Token & Secret
251
+ 5. Update `.env` with NEW tokens
252
+ 6. Restart your bot
253
+
254
+ **How to verify:** In "Keys and tokens", your Access Token should show "Created with Read and Write permissions"
105
255
 
106
- ### Autonomous Posting
256
+ ### "Could not authenticate you"
107
257
 
108
- When `TWITTER_POST_ENABLE=true`, the client automatically generates and posts tweets:
109
- - Configurable posting intervals with randomization
110
- - Character-based content generation
111
- - Support for long-form tweets (up to 4000 characters)
112
- - Dry-run mode for testing
258
+ Wrong credentials or using OAuth 2.0 instead of OAuth 1.0a.
113
259
 
114
- ### Timeline Monitoring
260
+ **Solution:**
261
+ - Use credentials from "Consumer Keys" section (API Key/Secret)
262
+ - Use credentials from "Authentication Tokens" section (Access Token/Secret)
263
+ - Do NOT use OAuth 2.0 Client ID, Client Secret, or Bearer Token
115
264
 
116
- The client monitors and processes the Twitter timeline:
117
- - **Weighted Algorithm**: Scores tweets based on user relationships, time, and relevance
118
- - **Latest Algorithm**: Processes tweets in chronological order
119
- - Configurable interaction limits and intervals
120
- - Smart caching to avoid duplicate processing
265
+ ### Bot Not Posting Automatically
121
266
 
122
- ### Interaction Handling
267
+ **Checklist:**
268
+ - โœ… Is `TWITTER_POST_ENABLE=true`?
269
+ - โœ… Is `@elizaos/plugin-bootstrap` installed?
270
+ - โœ… Does your character have `postExamples`?
271
+ - โœ… Check logs for "Twitter posting is ENABLED"
272
+ - โœ… Try `TWITTER_POST_IMMEDIATELY=true` for testing
123
273
 
124
- Automatically handles:
125
- - **Mentions**: Responds to tweets mentioning the bot
126
- - **Replies**: Handles replies to the bot's tweets
127
- - **Direct Messages**: Processes DMs when enabled
128
- - **Target Users**: Can be configured to only interact with specific users
274
+ ### Timeline Not Loading
129
275
 
130
- ### Search and Discovery
276
+ **Common causes:**
277
+ - Rate limiting (check Twitter Developer Portal)
278
+ - Invalid credentials
279
+ - Account restrictions
131
280
 
132
- - Timeline-based search and interaction
133
- - Configurable search intervals
134
- - Relevance-based filtering
135
- - User targeting with wildcard support
281
+ ### "Invalid or expired token"
136
282
 
137
- ### Advanced Features
283
+ Your tokens may have been revoked or regenerated.
138
284
 
139
- - **Request Queue**: Manages API rate limiting with exponential backoff
140
- - **Tweet Caching**: Efficient caching system for processed tweets
141
- - **Error Handling**: Robust retry mechanisms with configurable limits
142
- - **State Management**: Persistent state tracking across restarts
285
+ **Solution:**
286
+ 1. Go to Twitter Developer Portal
287
+ 2. Regenerate all tokens
288
+ 3. Update `.env`
289
+ 4. Restart bot
143
290
 
144
- ## Configuration Options
291
+ ## ๐Ÿ“š Advanced Features
145
292
 
146
293
  ### Timeline Algorithms
147
294
 
@@ -161,16 +308,16 @@ Automatically handles:
161
308
  # Interact with everyone (default)
162
309
  TWITTER_TARGET_USERS=
163
310
 
164
- # Interact with specific users
311
+ # Interact with specific users only
165
312
  TWITTER_TARGET_USERS=user1,user2,user3
166
313
 
167
- # Interact with everyone (explicit wildcard)
314
+ # Interact with everyone (explicit)
168
315
  TWITTER_TARGET_USERS=*
169
316
  ```
170
317
 
171
- ### Interval Configuration
318
+ ### Natural Posting Intervals
172
319
 
173
- All intervals support variance for more natural behavior:
320
+ All intervals support variance for more human-like behavior:
174
321
  ```bash
175
322
  # Base interval: 90-180 minutes
176
323
  TWITTER_POST_INTERVAL_MIN=90
@@ -179,9 +326,15 @@ TWITTER_POST_INTERVAL_MAX=180
179
326
  TWITTER_POST_INTERVAL_VARIANCE=0.2
180
327
  ```
181
328
 
182
- ## Development
329
+ ### Request Queue & Rate Limiting
183
330
 
184
- ### Testing
331
+ The plugin includes sophisticated rate limiting:
332
+ - Automatic retry with exponential backoff
333
+ - Request queue to prevent API abuse
334
+ - Configurable retry limits
335
+ - Built-in caching to reduce API calls
336
+
337
+ ## ๐Ÿงช Development & Testing
185
338
 
186
339
  ```bash
187
340
  # Run tests
@@ -194,56 +347,47 @@ DEBUG=eliza:* bun start
194
347
  TWITTER_DRY_RUN=true bun start
195
348
  ```
196
349
 
197
- ### Common Issues
198
-
199
- #### Authentication Failures
200
- - Verify all four API credentials are correctly set
201
- - Ensure your Twitter app has API v2 access enabled
202
- - Check that Access Token permissions match your use case
203
- - Verify your developer account is in good standing
204
-
205
- #### Rate Limiting
206
- - The client includes built-in rate limiting and retry mechanisms
207
- - Adjust `TWITTER_RETRY_LIMIT` if experiencing frequent failures
208
- - Consider increasing polling intervals for high-volume accounts
209
-
210
- #### No Interactions
211
- - Verify `TWITTER_SEARCH_ENABLE=true`
212
- - Check `TWITTER_TARGET_USERS` configuration
213
- - Ensure the timeline contains relevant content
214
- - Review `TWITTER_MAX_INTERACTIONS_PER_RUN` setting
215
-
216
- #### Timeline Issues
217
- - Try switching between "weighted" and "latest" algorithms
218
- - Adjust timeline weight parameters for better relevance
219
- - Check `TWITTER_POLL_INTERVAL` for timeline refresh rate
220
-
221
- ## Security Notes
222
-
223
- - Store credentials in environment variables, never in code
224
- - Use `.env.local` or similar for local development
225
- - Regularly rotate API keys and tokens
226
- - Monitor API usage in Twitter Developer Portal
227
- - Enable only necessary permissions for Access Tokens
228
-
229
- ## API Usage
230
-
231
- This plugin uses Twitter API v2 endpoints:
232
- - **Timeline endpoints**: For fetching home timeline and user tweets
233
- - **Tweet endpoints**: For posting tweets and fetching individual tweets
234
- - **User endpoints**: For user profile information
235
- - **Search endpoints**: For content discovery
236
-
237
- Monitor your API usage in the Twitter Developer Portal to avoid rate limits.
238
-
239
- ## Support
240
-
241
- For issues or questions:
242
- 1. Check the Common Issues section above
243
- 2. Enable debug logging: `DEBUG=eliza:*`
244
- 3. Verify your API credentials and permissions
245
- 4. Check Twitter API v2 status and limits
246
- 5. Open an issue with:
247
- - Error messages and logs
248
- - Configuration details (without credentials)
249
- - Steps to reproduce
350
+ ### Testing Checklist
351
+
352
+ 1. **Test Auth**: Check logs for successful Twitter login
353
+ 2. **Test Posting**: Set `TWITTER_POST_IMMEDIATELY=true`
354
+ 3. **Test Dry Run**: Use `TWITTER_DRY_RUN=true` first
355
+ 4. **Monitor Logs**: Look for "Twitter posting is ENABLED"
356
+
357
+ ## ๐Ÿ”’ Security Best Practices
358
+
359
+ - Store credentials in `.env` file (never commit!)
360
+ - Use `.env.local` for local development
361
+ - Regularly rotate API keys
362
+ - Monitor API usage in Developer Portal
363
+ - Enable only necessary permissions
364
+ - Review [Twitter's automation rules](https://help.twitter.com/en/rules-and-policies/twitter-automation)
365
+
366
+ ## ๐Ÿ“Š API Usage & Limits
367
+
368
+ This plugin uses Twitter API v2 endpoints efficiently:
369
+ - **Home Timeline**: Cached and refreshed periodically
370
+ - **Tweet Creation**: Rate limited automatically
371
+ - **User Lookups**: Cached to reduce calls
372
+ - **Search**: Configurable intervals
373
+
374
+ Monitor your usage at: https://developer.twitter.com/en/portal/dashboard
375
+
376
+ ## ๐Ÿ“– Additional Resources
377
+
378
+ - [Twitter API v2 Documentation](https://developer.twitter.com/en/docs/twitter-api)
379
+ - [Twitter OAuth 1.0a Guide](https://developer.twitter.com/en/docs/authentication/oauth-1-0a)
380
+ - [Rate Limits Reference](https://developer.twitter.com/en/docs/twitter-api/rate-limits)
381
+ - [ElizaOS Documentation](https://github.com/elizaos/eliza)
382
+
383
+ ## ๐Ÿค Contributing
384
+
385
+ Contributions are welcome! Please:
386
+ 1. Check existing issues first
387
+ 2. Follow the code style
388
+ 3. Add tests for new features
389
+ 4. Update documentation
390
+
391
+ ## ๐Ÿ“ License
392
+
393
+ This plugin is part of the ElizaOS project. See the main repository for license information.