← Back to Plugins
Tools

Twitter

jugs-eth By jugs-eth 👁 26 views ▲ 0 votes

OpenClaw twitter plugin

GitHub

Install

npm install
   ```

Configuration Example

{
  "data": {
    "id": "1234567890123456789",
    "text": "Hello from OpenClaw!",
    "created_at": "2024-01-01T12:00:00.000Z",
    "author_id": "987654321",
    "public_metrics": {
      "retweet_count": 5,
      "like_count": 12,
      "reply_count": 3,
      "quote_count": 1
    }
  }
}

README

# Twitter/X CLI Plugin for OpenClaw

A comprehensive command-line interface for Twitter/X that enables posting, engagement, analytics, and automation through the Twitter API.

## Features

- **Tweet Management**: Post tweets, threads, replies, quote tweets
- **Engagement**: Like, retweet, reply to tweets
- **Content Discovery**: Search tweets, browse timelines, check mentions
- **User Management**: Get profile info, followers, following lists
- **Direct Messages**: Send and receive DMs
- **Media Support**: Upload and attach images/videos
- **Analytics**: Get engagement metrics and tweet performance data
- **Automation**: Schedule tweets for later posting
- **Tweet Cleanup**: Delete tweets and manage your content

## Quick Start

1. **Install dependencies**:
   ```bash
   cd /root/.openclaw/workspace/skills/twitter
   npm install
   ```

2. **Set up credentials** (see [Setup Guide](./setup.md)):
   Add to `/root/.openclaw/.env`:
   ```bash
   TWITTER_API_KEY=your_api_key_here
   TWITTER_API_SECRET=your_api_secret_here
   TWITTER_ACCESS_TOKEN=your_access_token_here
   TWITTER_ACCESS_SECRET=your_access_secret_here
   TWITTER_BEARER_TOKEN=your_bearer_token_here
   ```

3. **Test the connection**:
   ```bash
   ./twitter.sh user your_username
   ```

## Commands

### Posting & Content Creation

```bash
# Post a simple tweet
./twitter.sh post "Hello from OpenClaw! 🚀"

# Post with media
./twitter.sh post "Check this out!" "https://example.com/image.png"

# Create a thread
./twitter.sh thread "1/3 Starting a thread..." "2/3 Middle of the thread" "3/3 End of thread"

# Reply to a tweet
./twitter.sh reply 1234567890123456789 "Great point!"

# Quote tweet
./twitter.sh quote 1234567890123456789 "This is so true!"
```

### Engagement

```bash
# Like a tweet
./twitter.sh like 1234567890123456789

# Retweet
./twitter.sh retweet 1234567890123456789

# Unlike a tweet
./twitter.sh unlike 1234567890123456789

# Delete your tweet
./twitter.sh delete 1234567890123456789
```

### Discovery & Research

```bash
# Search recent tweets
./twitter.sh search "OpenClaw AI" 20

# Get your timeline
./twitter.sh timeline 50

# Check mentions
./twitter.sh mentions 25

# Get user profile
./twitter.sh user elonmusk

# Get followers
./twitter.sh followers your_username 100

# Get following
./twitter.sh following your_username 100
```

### Direct Messages

```bash
# Send a DM
./twitter.sh dm-send friend_username "Hey there!"

# List recent DMs
./twitter.sh dm-list 20
```

### Media & Analytics

```bash
# Upload media (returns media_id)
./twitter.sh media-upload "https://example.com/video.mp4"

# Get tweet analytics
./twitter.sh analytics 1234567890123456789

# Schedule a tweet
./twitter.sh schedule "2024-12-31T23:59:00Z" "Happy New Year!"
```

## Advanced Usage

### Automation Examples

**Scheduled posting workflow**:
```bash
# Schedule multiple tweets
./twitter.sh schedule "2024-01-01T09:00:00Z" "Good morning! Starting the year strong 💪"
./twitter.sh schedule "2024-01-01T12:00:00Z" "Lunch break thoughts on AI development..."
./twitter.sh schedule "2024-01-01T18:00:00Z" "Wrapping up the day. Here's what I learned:"

# Set up cron to process scheduled tweets (add to crontab)
* * * * * cd /root/.openclaw/workspace/skills/twitter && node -e "const fs=require('fs');const{exec}=require('child_process');if(fs.existsSync('scheduled_tweets.json')){const tweets=JSON.parse(fs.readFileSync('scheduled_tweets.json'));const now=new Date();const ready=tweets.filter(t=>new Date(t.date)<=now);ready.forEach(t=>exec(\`./twitter.sh post '\${t.text}'\`));const remaining=tweets.filter(t=>new Date(t.date)>now);fs.writeFileSync('scheduled_tweets.json',JSON.stringify(remaining,null,2));}"
```

**Content research workflow**:
```bash
# Research trending topics
./twitter.sh search "AI trends 2024" 50 > ai_trends.json

# Monitor competitors
./twitter.sh user competitor_handle > competitor_profile.json
./twitter.sh timeline competitor_handle 100 > competitor_tweets.json

# Engagement monitoring
./twitter.sh mentions 100 > recent_mentions.json
./twitter.sh analytics your_popular_tweet_id > tweet_performance.json
```

**Community management**:
```bash
# Respond to mentions
./twitter.sh mentions 20 | jq -r '.data[].id' | while read tweet_id; do
  ./twitter.sh reply $tweet_id "Thanks for the mention! 🙏"
done

# Bulk follow back
./twitter.sh followers your_username 1000 | jq -r '.data[].username' | while read user; do
  echo "Consider following back: @$user"
done
```

### Integration with Other Tools

**Export to CSV**:
```bash
./twitter.sh search "your_brand" 100 | jq -r '.data[] | [.created_at, .author_id, .text, .public_metrics.like_count] | @csv' > mentions.csv
```

**Webhook integration**:
```bash
# Monitor mentions and send to webhook
./twitter.sh mentions 10 | curl -X POST your-webhook-url.com -H "Content-Type: application/json" -d @-
```

## Rate Limits & Best Practices

### Twitter API Rate Limits
- **Tweets**: 300 per 3-hour window
- **Likes**: 1000 per 24 hours  
- **Retweets**: 600 per 15 minutes
- **Follows**: 50 per 15 minutes
- **DMs**: 15 per 24 hours
- **Search**: 450 per 15 minutes

### Best Practices
- Use meaningful intervals between bulk actions
- Monitor API usage with analytics commands
- Cache user lookups when possible
- Use search filters to narrow results
- Schedule tweets during peak engagement hours

## Output Format

All commands return structured JSON:

```json
{
  "data": {
    "id": "1234567890123456789",
    "text": "Hello from OpenClaw!",
    "created_at": "2024-01-01T12:00:00.000Z",
    "author_id": "987654321",
    "public_metrics": {
      "retweet_count": 5,
      "like_count": 12,
      "reply_count": 3,
      "quote_count": 1
    }
  }
}
```

Errors are returned to stderr:
```json
{
  "error": "Twitter API error: Rate limit exceeded"
}
```

## Troubleshooting

### Common Issues

**Authentication errors**:
- Verify all 5 environment variables are set
- Check that tokens haven't expired
- Ensure app permissions include read/write/DM access

**Rate limiting**:
- Wait for rate limit window to reset
- Use bearer token endpoints when possible (read-only)
- Implement delays between bulk operations

**Media upload failures**:
- Ensure media URL is publicly accessible
- Check file size limits (images: 5MB, videos: 15MB)
- Verify supported formats (JPEG, PNG, GIF, MP4, MOV)

**Tweet posting issues**:
- Check character limits (280 for tweets)
- Avoid duplicate content (Twitter blocks exact duplicates)
- Ensure proper UTF-8 encoding

### Debug Mode

Set environment variable for verbose logging:
```bash
DEBUG=twitter:* ./twitter.sh search "test query"
```

## Setup Guide

For detailed credential setup instructions, see [setup.md](./setup.md).

## Deploy with PinchKit

Deploy this Twitter CLI plugin to your PinchKit infrastructure:

1. **Package the plugin**:
   ```bash
   cd /root/.openclaw/workspace/skills/twitter
   tar -czf twitter-plugin.tar.gz .
   ```

2. **Deploy via PinchKit CLI**:
   ```bash
   pinchkit deploy --type openclaw-plugin --file twitter-plugin.tar.gz --name twitter-cli
   ```

3. **Configure environment**:
   ```bash
   pinchkit env set TWITTER_API_KEY "your_api_key"
   pinchkit env set TWITTER_API_SECRET "your_api_secret"  
   pinchkit env set TWITTER_ACCESS_TOKEN "your_access_token"
   pinchkit env set TWITTER_ACCESS_SECRET "your_access_secret"
   pinchkit env set TWITTER_BEARER_TOKEN "your_bearer_token"
   ```

4. **Test deployment**:
   ```bash
   pinchkit exec twitter-cli "./twitter.sh user your_username"
   ```

5. **Scale & monitor**:
   ```bash
   pinchkit scale twitter-cli --instances 3
   pinchkit logs twitter-cli --follow
   pinchkit metrics twitter-cli
   ```

The plugin will be available across your PinchKit cluster with automatic load balancing and monitoring.

## Contributing

1. Fork this repository
2. Create a feature branch
3. Make your changes with tests
4. Submit a pull request

## License

MIT License - see LICENSE file for details.

## Support

- **Issues**: Create an issue in this repository
- **Documentation**: See SKILL.md for OpenClaw integration
- **API Reference**: [Twitter API Documentation](https://developer.twitter.com/en/docs)
tools

Comments

Sign in to leave a comment

Loading comments...