@elizaos/plugin-twitter 1.0.8 → 1.0.13
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 +181 -91
- package/dist/index.d.ts +126 -949
- package/dist/index.js +2021 -7284
- package/dist/index.js.map +1 -1
- package/package.json +202 -21
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/node-L7ZVN5QV.js +0 -40
- package/dist/node-L7ZVN5QV.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,116 +1,183 @@
|
|
|
1
1
|
# Eliza Twitter/X Client
|
|
2
2
|
|
|
3
|
-
This package provides Twitter/X integration for the Eliza AI agent.
|
|
3
|
+
This package provides Twitter/X integration for the Eliza AI agent using Twitter API v2.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
7
|
+
- Autonomous tweet posting with configurable intervals
|
|
8
|
+
- Timeline monitoring and interaction
|
|
9
|
+
- Mention and reply handling
|
|
9
10
|
- Search functionality
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
11
|
+
- Direct message support
|
|
12
|
+
- Advanced timeline algorithms with weighted scoring
|
|
13
|
+
- Action processing and automated responses
|
|
14
|
+
- Comprehensive caching system
|
|
13
15
|
|
|
14
16
|
## Setup Guide
|
|
15
17
|
|
|
16
18
|
### Prerequisites
|
|
17
19
|
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- ElevenLabs API key (if using Spaces with TTS)
|
|
20
|
+
- Twitter Developer Account with API v2 access
|
|
21
|
+
- Twitter API v2 credentials (API Key, API Secret, Access Token, Access Token Secret)
|
|
22
|
+
- Node.js and bun installed
|
|
22
23
|
|
|
23
24
|
### Step 1: Configure Environment Variables
|
|
24
25
|
|
|
25
26
|
Create or edit `.env` file in your project root:
|
|
26
27
|
|
|
27
28
|
```bash
|
|
28
|
-
# Twitter API Credentials
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
#
|
|
35
|
-
TWITTER_DRY_RUN=false
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
TWITTER_POLL_INTERVAL=120 # Poll interval in seconds
|
|
40
|
-
TWITTER_TARGET_USERS= # Comma-separated list of target users
|
|
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
|
|
34
|
+
|
|
35
|
+
# Basic Configuration
|
|
36
|
+
TWITTER_DRY_RUN=false # Set to true for testing without posting
|
|
37
|
+
TWITTER_TARGET_USERS= # Comma-separated usernames to target (use "*" for all)
|
|
38
|
+
TWITTER_RETRY_LIMIT=5 # Maximum retry attempts for failed operations
|
|
39
|
+
TWITTER_POLL_INTERVAL=120 # Timeline polling interval (seconds)
|
|
41
40
|
|
|
42
41
|
# Post Generation Settings
|
|
43
|
-
|
|
42
|
+
TWITTER_POST_ENABLE=false # Enable autonomous tweet posting
|
|
44
43
|
TWITTER_POST_INTERVAL_MIN=90 # Minimum interval between posts (minutes)
|
|
45
|
-
|
|
46
|
-
TWITTER_POST_IMMEDIATELY=false # Skip
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
TWITTER_POST_INTERVAL_MAX=180 # Maximum interval between posts (minutes)
|
|
45
|
+
TWITTER_POST_IMMEDIATELY=false # Skip intervals and post immediately
|
|
46
|
+
TWITTER_POST_INTERVAL_VARIANCE=0.2 # Random variance factor for posting intervals
|
|
47
|
+
|
|
48
|
+
# Interaction Settings
|
|
49
|
+
TWITTER_SEARCH_ENABLE=true # Enable timeline monitoring and interactions
|
|
50
|
+
TWITTER_INTERACTION_INTERVAL_MIN=15 # Minimum interval between interactions (minutes)
|
|
51
|
+
TWITTER_INTERACTION_INTERVAL_MAX=30 # Maximum interval between interactions (minutes)
|
|
52
|
+
TWITTER_INTERACTION_INTERVAL_VARIANCE=0.3 # Random variance for interaction intervals
|
|
53
|
+
TWITTER_AUTO_RESPOND_MENTIONS=true # Automatically respond to mentions
|
|
54
|
+
TWITTER_AUTO_RESPOND_REPLIES=true # Automatically respond to replies
|
|
55
|
+
TWITTER_MAX_INTERACTIONS_PER_RUN=10 # Maximum interactions processed per cycle
|
|
56
|
+
|
|
57
|
+
# Timeline Algorithm Configuration
|
|
58
|
+
TWITTER_TIMELINE_ALGORITHM=weighted # Algorithm: "weighted" or "latest"
|
|
59
|
+
TWITTER_TIMELINE_USER_BASED_WEIGHT=3 # Weight for user-based scoring
|
|
60
|
+
TWITTER_TIMELINE_TIME_BASED_WEIGHT=2 # Weight for time-based scoring
|
|
61
|
+
TWITTER_TIMELINE_RELEVANCE_WEIGHT=5 # Weight for relevance scoring
|
|
62
|
+
|
|
63
|
+
# Advanced Settings
|
|
64
|
+
TWITTER_MAX_TWEET_LENGTH=4000 # Maximum tweet length (for threads)
|
|
65
|
+
TWITTER_DM_ONLY=false # Only interact via direct messages
|
|
66
|
+
TWITTER_ENABLE_ACTION_PROCESSING=false # Enable timeline action processing
|
|
67
|
+
TWITTER_ACTION_INTERVAL=240 # Action processing interval (minutes)
|
|
61
68
|
```
|
|
62
69
|
|
|
63
70
|
### Step 2: Initialize the Client
|
|
64
71
|
|
|
65
72
|
```typescript
|
|
66
|
-
import { TwitterClientInterface } from "@elizaos/twitter";
|
|
73
|
+
import { TwitterClientInterface } from "@elizaos/plugin-twitter";
|
|
67
74
|
|
|
68
75
|
const twitterPlugin = {
|
|
69
76
|
name: "twitter",
|
|
70
77
|
description: "Twitter client",
|
|
71
|
-
|
|
78
|
+
services: [TwitterService],
|
|
72
79
|
};
|
|
73
80
|
|
|
74
81
|
// Register with your Eliza runtime
|
|
75
82
|
runtime.registerPlugin(twitterPlugin);
|
|
76
83
|
```
|
|
77
84
|
|
|
85
|
+
## Authentication
|
|
86
|
+
|
|
87
|
+
This plugin uses **Twitter API v2** with OAuth 1.0a authentication. You need:
|
|
88
|
+
|
|
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
|
|
92
|
+
|
|
93
|
+
### Getting Twitter API Credentials
|
|
94
|
+
|
|
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`)
|
|
103
|
+
|
|
78
104
|
## Features
|
|
79
105
|
|
|
80
|
-
###
|
|
106
|
+
### Autonomous Posting
|
|
107
|
+
|
|
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
|
|
113
|
+
|
|
114
|
+
### Timeline Monitoring
|
|
115
|
+
|
|
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
|
|
121
|
+
|
|
122
|
+
### Interaction Handling
|
|
123
|
+
|
|
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
|
|
129
|
+
|
|
130
|
+
### Search and Discovery
|
|
131
|
+
|
|
132
|
+
- Timeline-based search and interaction
|
|
133
|
+
- Configurable search intervals
|
|
134
|
+
- Relevance-based filtering
|
|
135
|
+
- User targeting with wildcard support
|
|
81
136
|
|
|
82
|
-
|
|
83
|
-
- Regular tweets (≤280 characters)
|
|
84
|
-
- Long-form tweets (Note Tweets)
|
|
85
|
-
- Media tweets (with images/videos)
|
|
137
|
+
### Advanced Features
|
|
86
138
|
|
|
87
|
-
|
|
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
|
|
88
143
|
|
|
89
|
-
|
|
90
|
-
- Mentions
|
|
91
|
-
- Replies
|
|
92
|
-
- Quote tweets
|
|
93
|
-
- Direct messages
|
|
144
|
+
## Configuration Options
|
|
94
145
|
|
|
95
|
-
###
|
|
146
|
+
### Timeline Algorithms
|
|
96
147
|
|
|
97
|
-
|
|
148
|
+
**Weighted Algorithm** (default):
|
|
149
|
+
- Combines user relationship, time, and relevance scores
|
|
150
|
+
- Prioritizes tweets from important users
|
|
151
|
+
- Balances recent content with relevant older content
|
|
98
152
|
|
|
99
|
-
|
|
153
|
+
**Latest Algorithm**:
|
|
154
|
+
- Processes tweets in chronological order
|
|
155
|
+
- Simpler, more predictable behavior
|
|
156
|
+
- Good for high-volume timelines
|
|
100
157
|
|
|
101
|
-
|
|
102
|
-
- Speech-to-Text (STT) for transcription
|
|
103
|
-
- Text-to-Speech (TTS) via ElevenLabs
|
|
104
|
-
- Speaker management
|
|
105
|
-
- Idle monitoring
|
|
106
|
-
- Recording capabilities
|
|
158
|
+
### Target User Configuration
|
|
107
159
|
|
|
108
|
-
|
|
160
|
+
```bash
|
|
161
|
+
# Interact with everyone (default)
|
|
162
|
+
TWITTER_TARGET_USERS=
|
|
163
|
+
|
|
164
|
+
# Interact with specific users
|
|
165
|
+
TWITTER_TARGET_USERS=user1,user2,user3
|
|
166
|
+
|
|
167
|
+
# Interact with everyone (explicit wildcard)
|
|
168
|
+
TWITTER_TARGET_USERS=*
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Interval Configuration
|
|
109
172
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
173
|
+
All intervals support variance for more natural behavior:
|
|
174
|
+
```bash
|
|
175
|
+
# Base interval: 90-180 minutes
|
|
176
|
+
TWITTER_POST_INTERVAL_MIN=90
|
|
177
|
+
TWITTER_POST_INTERVAL_MAX=180
|
|
178
|
+
# With 20% variance: actual range ~72-216 minutes
|
|
179
|
+
TWITTER_POST_INTERVAL_VARIANCE=0.2
|
|
180
|
+
```
|
|
114
181
|
|
|
115
182
|
## Development
|
|
116
183
|
|
|
@@ -118,42 +185,65 @@ Optional Discord-based approval system for tweets:
|
|
|
118
185
|
|
|
119
186
|
```bash
|
|
120
187
|
# Run tests
|
|
121
|
-
|
|
188
|
+
bun test
|
|
189
|
+
|
|
190
|
+
# Run with debug logging
|
|
191
|
+
DEBUG=eliza:* bun start
|
|
122
192
|
|
|
123
|
-
#
|
|
124
|
-
|
|
193
|
+
# Test without posting
|
|
194
|
+
TWITTER_DRY_RUN=true bun start
|
|
125
195
|
```
|
|
126
196
|
|
|
127
197
|
### Common Issues
|
|
128
198
|
|
|
129
|
-
####
|
|
130
|
-
- Verify credentials
|
|
131
|
-
-
|
|
132
|
-
-
|
|
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
|
|
133
209
|
|
|
134
|
-
####
|
|
135
|
-
- Verify
|
|
136
|
-
- Check
|
|
137
|
-
-
|
|
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
|
|
138
215
|
|
|
139
|
-
####
|
|
140
|
-
-
|
|
141
|
-
-
|
|
142
|
-
-
|
|
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
|
|
143
220
|
|
|
144
221
|
## Security Notes
|
|
145
222
|
|
|
146
|
-
-
|
|
147
|
-
- Use
|
|
148
|
-
-
|
|
149
|
-
- Monitor API usage
|
|
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.
|
|
150
238
|
|
|
151
239
|
## Support
|
|
152
240
|
|
|
153
241
|
For issues or questions:
|
|
154
|
-
1. Check the Common Issues section
|
|
155
|
-
2.
|
|
156
|
-
3.
|
|
157
|
-
|
|
158
|
-
|
|
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)
|
|
159
249
|
- Steps to reproduce
|