Package Exports
- @defikitdotnet/x-ai-combat
- @defikitdotnet/x-ai-combat/backend
- @defikitdotnet/x-ai-combat/contexts
- @defikitdotnet/x-ai-combat/frontend
- @defikitdotnet/x-ai-combat/models
- @defikitdotnet/x-ai-combat/package.json
Readme
XCombatAI
XCombatAI is a social media engagement template for the Agent Framework that utilizes the @defikitdotnet/agent-twitter-client package for Twitter interactions without requiring the Twitter API.
Features
- Login with X API: A dedicated API endpoint to handle Twitter authentication for users on the web platform
- Interaction Scanner: Scheduled job that scans posts mentioning the agent and identifies user interactions
- Bot Responder: Monitors posts and replies to unlinked users with contextual AI-generated prompts
- Fame Points System: Track and reward user engagement with a leaderboard
Architecture
The system consists of the following components:
Resource Models
- User: Stores information about users who link their Twitter accounts via the Login with X API
- Post: Uses the
Tweet
class from @defikitdotnet/agent-twitter-client to store tweet data - Interaction: Tracks user interactions (likes, retweets, quotes, replies) with posts mentioning the agent
API Endpoints
- Full CRUD operations for User, Post, and Interaction management
- Custom endpoints for:
- Login with X API (Twitter OAuth flow)
- Fetching posts interacted by users
- Retrieving interaction statistics
Plugins
- InteractionScanner: Scans Twitter for posts mentioning the agent and identifies user interactions
- BotResponder: Monitors posts and replies to unlinked users with contextual prompts
Services
- AI Service: Powered by Google Gemini to generate contextual reply prompts
Frontend Components
- PostPanel: Displays a list of posts a user has interacted with
- LeaderboardPanel: Ranks users based on Fame Points calculated from interactions
Setup
- Clone the repository
- Install dependencies:
npm install
- Create a
.env
file based on.env.example
with your Twitter credentials and other configuration - Run the development server:
npm run dev
Environment Variables
PORT
: Server port (default: 3000)DATABASE_URL
: Postgres database connection stringJWT_SECRET
: Secret key for JWT tokensTWITTER_USERNAME
: Twitter username for the bot accountTWITTER_PASSWORD
: Twitter password for the bot accountTWITTER_EMAIL
: Twitter email for the bot account (optional)AGENT_TWITTER_HANDLE
: Twitter handle for the agent (default: @XCombatAI)GEMINI_API_KEY
: Google Gemini API key for AI-generated repliesTELEGRAM_BOT_TOKEN
: Telegram bot token for notificationsTELEGRAM_CHAT_ID
: Telegram chat ID for notificationsWEB_PLATFORM_URL
: URL to your web platform for the "Login with X" flow
Fame Points System
Fame Points are calculated as follows:
- Likes: 0.5 points
- Retweets: 2 points
- Quotes: 2 points
- Replies: 1 point
Authentication Options
Regular Authentication
The application supports regular username/password authentication for Twitter:
TWITTER_USERNAME=your_username
TWITTER_PASSWORD=your_password
TWITTER_EMAIL=your_email
Cookie-Based Authentication
To bypass the login process entirely, you can provide Twitter cookies directly:
- Extract cookies from a browser session where you're logged into Twitter
- Format them as a JSON array and set in your environment:
TWITTER_COOKIES=[ ... cookie array ... ]
To get your cookies:
- Log in to Twitter using the application once
- Use the provided utility to export cookies:
import { TwitterService } from './services/twitter-service';
async function exportCookies() {
const service = TwitterService.getInstance();
await service.initialize();
const cookieJson = await service.getCookiesForExport();
console.log('Add this to your .env file:');
console.log(`TWITTER_COOKIES='${cookieJson}'`);
}
Cookie Caching with Redis
For improved reliability, the app can cache cookies using Redis:
REDIS_URL=redis://localhost:6379
When Redis is configured, successful logins will cache cookies for future use, reducing the need for frequent logins.
License
ISC