@elizaos/plugin-twitter 0.1.8-alpha.1
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/LICENSE +21 -0
- package/README.md +275 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Shaw Walters, aka Moon aka @lalalune
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# @elizaos/plugin-twitter
|
|
2
|
+
|
|
3
|
+
A plugin for Twitter/X integration, providing automated tweet posting capabilities with character-aware content generation.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This plugin provides functionality to:
|
|
8
|
+
|
|
9
|
+
- Compose context-aware tweets
|
|
10
|
+
- Post tweets to Twitter/X platform
|
|
11
|
+
- Handle authentication and session management
|
|
12
|
+
- Support premium Twitter features
|
|
13
|
+
- Manage tweet length restrictions
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @elizaos/plugin-twitter
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
The plugin requires the following environment variables:
|
|
24
|
+
|
|
25
|
+
```env
|
|
26
|
+
TWITTER_USERNAME=your_username
|
|
27
|
+
TWITTER_PASSWORD=your_password
|
|
28
|
+
TWITTER_EMAIL=your_email # Optional: for 2FA
|
|
29
|
+
TWITTER_2FA_SECRET=your_2fa_secret # Optional: for 2FA
|
|
30
|
+
TWITTER_PREMIUM=false # Optional: enables premium features
|
|
31
|
+
TWITTER_DRY_RUN=false # Optional: test without posting
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Import and register the plugin in your Eliza configuration:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { twitterPlugin } from "@elizaos/plugin-twitter";
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
plugins: [twitterPlugin],
|
|
43
|
+
// ... other configuration
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
### Tweet Composition
|
|
50
|
+
|
|
51
|
+
The plugin uses context-aware templates to generate appropriate tweets:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { postAction } from "@elizaos/plugin-twitter";
|
|
55
|
+
|
|
56
|
+
// Tweet will be composed based on context and character limits
|
|
57
|
+
const result = await postAction.handler(runtime, message, state);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Tweet Posting
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
// Post with automatic content generation
|
|
64
|
+
await postAction.handler(runtime, message, state);
|
|
65
|
+
|
|
66
|
+
// Dry run mode (for testing)
|
|
67
|
+
process.env.TWITTER_DRY_RUN = "true";
|
|
68
|
+
await postAction.handler(runtime, message, state);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
### Building
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm run build
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Testing
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm run test
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Development Mode
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm run dev
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Dependencies
|
|
92
|
+
|
|
93
|
+
- `@elizaos/core`: Core Eliza functionality
|
|
94
|
+
- `agent-twitter-client`: Twitter API client
|
|
95
|
+
- `tsup`: Build tool
|
|
96
|
+
- Other standard dependencies listed in package.json
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### Core Interfaces
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
interface TweetContent {
|
|
104
|
+
text: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Tweet Schema
|
|
108
|
+
const TweetSchema = z.object({
|
|
109
|
+
text: z.string().describe("The text of the tweet"),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Action Interface
|
|
113
|
+
interface Action {
|
|
114
|
+
name: "POST_TWEET";
|
|
115
|
+
similes: string[];
|
|
116
|
+
description: string;
|
|
117
|
+
validate: (
|
|
118
|
+
runtime: IAgentRuntime,
|
|
119
|
+
message: Memory,
|
|
120
|
+
state?: State
|
|
121
|
+
) => Promise<boolean>;
|
|
122
|
+
handler: (
|
|
123
|
+
runtime: IAgentRuntime,
|
|
124
|
+
message: Memory,
|
|
125
|
+
state?: State
|
|
126
|
+
) => Promise<boolean>;
|
|
127
|
+
examples: Array<Array<any>>;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Plugin Methods
|
|
132
|
+
|
|
133
|
+
- `postAction.handler`: Main method for posting tweets
|
|
134
|
+
- `postAction.validate`: Validates Twitter credentials
|
|
135
|
+
- `composeTweet`: Internal method for tweet generation
|
|
136
|
+
- `postTweet`: Internal method for tweet posting
|
|
137
|
+
|
|
138
|
+
## Common Issues/Troubleshooting
|
|
139
|
+
|
|
140
|
+
### Issue: Authentication Failures
|
|
141
|
+
|
|
142
|
+
- **Cause**: Invalid credentials or 2FA configuration
|
|
143
|
+
- **Solution**: Verify credentials and 2FA setup
|
|
144
|
+
|
|
145
|
+
### Issue: Tweet Length Errors
|
|
146
|
+
|
|
147
|
+
- **Cause**: Content exceeds Twitter's character limit
|
|
148
|
+
- **Solution**: Enable TWITTER_PREMIUM for extended tweets or ensure content is within limits
|
|
149
|
+
|
|
150
|
+
### Issue: Rate Limiting
|
|
151
|
+
|
|
152
|
+
- **Cause**: Too many requests in short time
|
|
153
|
+
- **Solution**: Implement proper request throttling
|
|
154
|
+
|
|
155
|
+
## Security Best Practices
|
|
156
|
+
|
|
157
|
+
- Store credentials securely using environment variables
|
|
158
|
+
- Use 2FA when possible
|
|
159
|
+
- Implement proper error handling
|
|
160
|
+
- Keep dependencies updated
|
|
161
|
+
- Use dry run mode for testing
|
|
162
|
+
- Monitor Twitter API usage
|
|
163
|
+
|
|
164
|
+
## Template System
|
|
165
|
+
|
|
166
|
+
The plugin uses a sophisticated template system for tweet generation:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const tweetTemplate = `
|
|
170
|
+
# Context
|
|
171
|
+
{{recentMessages}}
|
|
172
|
+
|
|
173
|
+
# Topics
|
|
174
|
+
{{topics}}
|
|
175
|
+
|
|
176
|
+
# Post Directions
|
|
177
|
+
{{postDirections}}
|
|
178
|
+
|
|
179
|
+
# Recent interactions
|
|
180
|
+
{{recentPostInteractions}}
|
|
181
|
+
|
|
182
|
+
# Task
|
|
183
|
+
Generate a tweet that:
|
|
184
|
+
1. Relates to the recent conversation
|
|
185
|
+
2. Matches the character's style
|
|
186
|
+
3. Is concise and engaging
|
|
187
|
+
4. Must be UNDER 180 characters
|
|
188
|
+
5. Speaks from the perspective of {{agentName}}
|
|
189
|
+
`;
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Future Enhancements
|
|
193
|
+
|
|
194
|
+
1. **Content Generation**
|
|
195
|
+
|
|
196
|
+
- Advanced context awareness
|
|
197
|
+
- Multi-language support
|
|
198
|
+
- Style customization
|
|
199
|
+
- Hashtag optimization
|
|
200
|
+
- Media generation
|
|
201
|
+
- Thread composition
|
|
202
|
+
|
|
203
|
+
2. **Engagement Features**
|
|
204
|
+
|
|
205
|
+
- Auto-reply system
|
|
206
|
+
- Engagement analytics
|
|
207
|
+
- Follower management
|
|
208
|
+
- Interaction scheduling
|
|
209
|
+
- Sentiment analysis
|
|
210
|
+
- Community management
|
|
211
|
+
|
|
212
|
+
3. **Tweet Management**
|
|
213
|
+
|
|
214
|
+
- Thread management
|
|
215
|
+
- Tweet scheduling
|
|
216
|
+
- Content moderation
|
|
217
|
+
- Archive management
|
|
218
|
+
- Delete automation
|
|
219
|
+
- Edit optimization
|
|
220
|
+
|
|
221
|
+
4. **Analytics Integration**
|
|
222
|
+
|
|
223
|
+
- Performance tracking
|
|
224
|
+
- Engagement metrics
|
|
225
|
+
- Audience insights
|
|
226
|
+
- Trend analysis
|
|
227
|
+
- ROI measurement
|
|
228
|
+
- Custom reporting
|
|
229
|
+
|
|
230
|
+
5. **Authentication**
|
|
231
|
+
|
|
232
|
+
- OAuth improvements
|
|
233
|
+
- Multi-account support
|
|
234
|
+
- Session management
|
|
235
|
+
- Rate limit handling
|
|
236
|
+
- Security enhancements
|
|
237
|
+
- Backup mechanisms
|
|
238
|
+
|
|
239
|
+
6. **Developer Tools**
|
|
240
|
+
- Enhanced debugging
|
|
241
|
+
- Testing framework
|
|
242
|
+
- Documentation generator
|
|
243
|
+
- Integration templates
|
|
244
|
+
- Error handling
|
|
245
|
+
- Logging system
|
|
246
|
+
|
|
247
|
+
We welcome community feedback and contributions to help prioritize these enhancements.
|
|
248
|
+
|
|
249
|
+
## Contributing
|
|
250
|
+
|
|
251
|
+
Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.
|
|
252
|
+
|
|
253
|
+
## Credits
|
|
254
|
+
|
|
255
|
+
This plugin integrates with and builds upon several key technologies:
|
|
256
|
+
|
|
257
|
+
- [Twitter/X API](https://developer.twitter.com/en/docs): Official Twitter platform API
|
|
258
|
+
- [agent-twitter-client](https://www.npmjs.com/package/agent-twitter-client): Twitter API client library
|
|
259
|
+
- [Zod](https://github.com/colinhacks/zod): TypeScript-first schema validation
|
|
260
|
+
|
|
261
|
+
Special thanks to:
|
|
262
|
+
|
|
263
|
+
- The Twitter/X Developer Platform team
|
|
264
|
+
- The agent-twitter-client maintainers for API integration tools
|
|
265
|
+
- The Eliza community for their contributions and feedback
|
|
266
|
+
|
|
267
|
+
For more information about Twitter/X integration capabilities:
|
|
268
|
+
|
|
269
|
+
- [Twitter API Documentation](https://developer.twitter.com/en/docs)
|
|
270
|
+
- [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard)
|
|
271
|
+
- [Twitter API Best Practices](https://developer.twitter.com/en/docs/twitter-api/rate-limits)
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
This plugin is part of the Eliza project. See the main project repository for license information.
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elizaos/plugin-twitter",
|
|
3
|
+
"version": "0.1.8-alpha.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"@elizaos/source": "./src/index.ts",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@elizaos/core": "0.1.8-alpha.1",
|
|
23
|
+
"agent-twitter-client": "0.0.18",
|
|
24
|
+
"tsup": "8.3.5"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"vitest": "^1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup --format esm --dts",
|
|
31
|
+
"dev": "tsup --format esm --dts --watch",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:watch": "vitest"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "a7f2f8da256a3e5a21f2096f921eae246303ed98",
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|