enhancementgood first issueintegrationnew-featurenew-integration
Repository metrics
- Stars
- (1,930 stars)
- PR merge metrics
- (PR metrics pending)
Description
Description
Add Twitter/X integration to sync tweets, mentions, likes, followers, and social engagement activity into CORE.
Reference Implementations
Existing Integrations (use as templates)
integrations/github/- Similar event-driven systemintegrations/linear/- Project management integrationintegrations/slack/- For messaging reference
Required Files Structure
integrations/twitter/
├── src/
│ ├── index.ts # Main entry, OAuth spec
│ ├── schedule.ts # Sync logic
│ ├── utils.ts # X API utilities
│ ├── account-create.ts # OAuth setup
│ └── create-activity.ts # Activity formatting
├── package.json
├── tsup.config.ts
└── README.md
X (Twitter) API v2 Integration
OAuth Setup
- Use OAuth 2.0 (Authorization Code Flow with PKCE)
- Authorization URL:
https://x.com/i/oauth2/authorize - Token URL:
https://api.x.com/2/oauth2/token - Required scopes:
tweet.read- Read tweetstweet.write- Post and delete tweetsusers.read- Read user profile informationfollows.read- Read following/followers listsfollows.write- Follow/unfollow userslike.read- Read liked tweetslike.write- Like/unlike tweetsbookmark.read- Read bookmarkslist.read- Read listsoffline.access- Refresh token support (tokens expire after 2 hours without this)space.read- Read Spacesdm.read- Read direct messages
Base URL
https://api.x.com/2(X API v2)
Key Endpoints
POST /2/tweets- Create a tweetDELETE /2/tweets/{id}- Delete a tweetGET /2/tweets/{id}- Get a tweet by IDGET /2/tweets- Get multiple tweets by IDsGET /2/tweets/search/recent- Search recent tweets (last 7 days)GET /2/tweets/search/all- Full-archive search (Academic/Enterprise)GET /2/users/{id}- Get user by IDGET /2/users/by/username/{username}- Get user by usernameGET /2/users/me- Get authenticated userGET /2/users/{id}/tweets- Get user's tweets (timeline)GET /2/users/{id}/mentions- Get user's mentionsGET /2/users/{id}/followers- Get user's followersGET /2/users/{id}/following- Get user's followingPOST /2/users/{id}/following- Follow a userDELETE /2/users/{source_id}/following/{target_id}- Unfollow a userGET /2/users/{id}/liked_tweets- Get user's liked tweetsPOST /2/users/{id}/likes- Like a tweetDELETE /2/users/{id}/likes/{tweet_id}- Unlike a tweetGET /2/users/{id}/bookmarks- Get bookmarksGET /2/users/{id}/list_memberships- Get lists user is a member ofGET /2/tweets/{id}/retweeted_by- Users who retweetedGET /2/tweets/{id}/liking_users- Users who likedGET /2/tweets/{id}/quote_tweets- Get quote tweetsGET /2/dm_events- Get DM events
Events to Track
-
Tweet Events
- Tweet posted
- Tweet deleted
- Tweet reply posted
- Quote tweet created
-
Engagement Events
- Tweet liked/unliked
- Tweet retweeted
- Tweet bookmarked
- Tweet replied to
-
Mention Events
- User mentioned in tweet
- User mentioned in reply
-
Follow Events
- New follower gained
- User followed someone
- User unfollowed
-
DM Events
- Direct message received
- Direct message sent
Implementation Tasks
- Set up basic integration structure following
integrations/github/src/index.tspattern - Implement OAuth 2.0 with PKCE flow in
account-create.ts - Create X API utilities in
utils.tswith tweet expansion helpers - Implement sync logic in
schedule.tsfor timeline, mentions, and engagement - Convert X events to CORE activity format
- Handle tweet expansions (author, media, referenced tweets)
- Implement pagination with pagination tokens
- Add error handling and rate limiting
- Create integration documentation
- Add to
integrations/README.md
Technical Notes
- X API v2 is the current version; v1.1 is legacy
- OAuth 2.0 with PKCE is required (not basic OAuth 2.0)
- Access tokens expire after 2 hours; use
offline.accessscope for refresh tokens - Refresh tokens can be used to obtain new access tokens
- API access tiers: Free, Basic ($100/mo), Pro ($5,000/mo), Enterprise
- Free: Tweet posting + reading + user lookup (limited)
- Basic: 10,000 tweets/month read, 50,000 users/month
- Pro: 1M tweets/month read, full search archive
- Use
tweet.fields,user.fields,expansionsquery params to control response data - Rate limits vary by endpoint and tier (e.g., 300 requests/15 min for tweet lookup on Basic)
- No native webhook support in v2 for most events; use polling
- Filtered stream available for real-time tweet matching (Pro+ tier)
Resources
- X API v2 Documentation
- X API v2 Authentication Mapping
- OAuth 2.0 Authorization Code with PKCE
- X API v2 Endpoints
- X Developer Portal
- twitter-api-v2 npm package
Labels
enhancement, integration, new-feature