XBot AI is an X-based intelligent agent that integrates Java Spring Boot, Gemini AI for getting trends and post generation, and blockchain logging on NEAR Testnet. Users interact with the bot via X mentions and replies, enabling real-time trend analysis, AI-generated posts, and transparent blockchain logging.
- X (formerly Twitter) Integration: Users can interact with the bot via X mentions and replies.
- Trending Topics Analysis: Fetch real-time trending topics using Gemini.
- AI-Powered Post Generation: Uses Gemini AI to create engaging posts based on selected trends.
- Blockchain Logging (NEAR Testnet): Logs posts and interactions for transparency.
- React-Based UI: A dashboard for managing accounts, checking blockchain logs.
🎯 This project was created for the One Trillion Agents Hackathon.
Technology | Version | Usage |
---|---|---|
Java 23+ (Spring Boot) | v3.4.2 | Backend for fetching data from X, AI content generation, blockchain API integration |
Apache Maven | v3.9.9 | Dependency management & project build system for Java |
Lombok | v1.18.36 | Java annotation library to reduce boilerplate code |
Vite, React, TypeScript | - | UI for bot management & monitoring logs in blockchain |
Node.js | v23.4.0 | JavaScript runtime for Vite & frontend tooling |
npm, npx | v10.9.2 | Package management & script execution for frontend |
Git & GitHub | - | Version control & code hosting |
Postman | 11.33.5 | API testing |
IntelliJ IDEA | 2024.3.3 | Development environment |
Component | Version | Usage |
---|---|---|
NEAR Protocol | - | Blockchain platform for smart contracts, transaction processing |
NEAR CLI | v4.0.13 | Command-line interface for NEAR blockchain interaction |
Node.js, JavaScript, WebAssembly (WASM) | - | Smart contract deployment, method execution via near-api-js, NEAR interaction |
UnencryptedFileSystemKeyStore | - | NEAR authentication & key storage (.near-credentials) |
WSL for Ubuntu | - | NEAR contract compilation & deployment |
MyNearWallet | - | NEAR Testnet wallet |
API | Plan | Usage |
---|---|---|
X API | Free | X API v2 (OAuth 1.0a via ScribeJava) |
Component | Usage |
---|---|
X Developer Platform | Two developer accounts for XBot AI (user & bot) |
Endpoint | Usage |
---|---|
POST /2/tweets |
Post publishing |
GET /2/users/:id/mentions |
Replying to mentions |
GET /2/tweets/search/recent |
Searching for recent posts |
GET /2/users/by/username/:username |
Fetching user details |
Database | Usage |
---|---|
H2 (SQL), JPA, Lombok, Spring Boot | Temporary local storage, ORM, and entity relationship management |
User-SocialAccount Mapping | One-to-One entity linkage between User & SocialAccount/SocialAccountBot |
JWT (JSON Web Token) | Authentication & session management |
Service | Model - | Usage |
---|---|---|
Gemini API (Google Cloud Console) | gemini-1.5-flash | Get trends & generate post |
git clone https://github.com/vero-git-hub/xbot-ai.git
cd xbot-ai
✅ Run backend service, start the Spring Boot service (Java):
Create a file named application-local.properties in resources (example: src/main/resources/application-local-example.properties
). Fill in the file with your credentials:
- Create an account on Google Cloud.
- Create a new project in Google Cloud Console
- Enable Gemini API
- Generate an API Key:
- Go to API & Services > Credentials
- Click "Create Credentials" > "API key"
- Add the API key to
src/main/resources/application-local.properties
:
google.cloud.api.key=your_google_cloud_api_key
On Windows (PowerShell):
[Convert]::ToBase64String((1..64 | ForEach-Object {Get-Random -Maximum 256}))
On Linux/macOS:
openssl rand -base64 64
Add the generated secret key to src/main/resources/application.properties:
jwt.secret=your_jwt_secret
mvn spring-boot:run
✅ Run frontend service, start Node.js (React UI):
cd frontend
npm install
npm run dev
-
Open the UI interface:
🔗 Go to http://localhost:5173/
-
Register a user:
- Click REGISTER → Enter your details → Click REGISTER
- You will be redirected to the login page
- Enter the credentials you just registered → Click LOGIN
🔹 Click "CONNECT YOUR ACCOUNT X"
Fill in the fields with your credentials. How to find them?
- Log in or sign up on X Developer Platform
- Go to Developer Dashboard
- In the left sidebar, click Projects & Apps, and select your project (default one)
- In the User authentication settings block, click Edit and configure:
- App permissions:
Read and write
- Type of App:
Web App, Automated App, or Bot
- App info:
- Callback URI / Redirect URL:
http://localhost:8080/auth/callback
- Website URL: (Any valid URL, e.g., GitHub repo)
- Callback URI / Redirect URL:
- Click Save
- Generate keys in Keys and Tokens tab:
Field | Value |
---|---|
Username | X account username |
API Key | Consumer Keys: API Key |
API Secret | Consumer Keys: API Secret |
Access Token | Authentication Tokens: Access Token |
Access Token Secret | Authentication Tokens: Access Token Secret |
- Get the User ID:
-
Retrieve the Bearer Token from the Keys and tokens tab
-
Use Postman or another API tool to make a request:
GET https://api.twitter.com/2/users/by/username/YOUR_USERNAME
- Add the header:
Authorization: Bearer YOUR_BEARER_TOKEN
- The response will contain an
id
field. Use this as User ID in the UI.
- Click Save Settings → Back to Dashboard
🔹 Click "CONNECT BOT ACCOUNT X" and follow the same steps as for the personal account.
📌 Note: Use your bot's username when mentioning the bot (e.g., @your_bot
).
- Install NEAR CLI:
npm install -g near-cli
near --version
- Create a MyNearWallet account on the Testnet:
near login --networkId testnet
This will store your credentials locally:
C:\Users\<YOUR_USERNAME>\.near-credentials\testnet
- Deploy the smart contract:
The contract is already compiled into .wasm format and located at:
blockchain/ubuntu/near-logger-contract.wasm
To deploy it to your Testnet account, run:
cd blockchain
near deploy [your-name].testnet ubuntu/near-logger-contract.wasm
npm install near-api-js
- Open your X account and post:
@[your_bot] trends
-
Set Who can reply? → Only accounts you mention can reply → Post
-
Uncomment line 88:
src/main/java/org/example/xbotai/service/core/impl/SocialMediaBotMentionService.java
@Scheduled(fixedDelay = 900000)
This line enables bot mention tracking.
❇️ API Free Plan has limitations. You can see them in X Developer Platform It's recommended to enable it only when everything is set up. ❇️
- Start both servers:
mvn spring-boot:run
npm run dev
- Check if the bot responds:
Enter your country to search for trends (United States, Canada)
- Reply:
country United States
- Restart the Java server (to activate an additional endpoint to search for bot mentions):
mvn spring-boot:run
- The bot will fetch trends and respond:
Trend1, Trend2, Trend3
- Reply with a trend:
trend [selected-trend]
- The bot will generate a post and publish it after 15 minutes.
✅ If everything works correctly, you will see:
The post was posted on your behalf. Contact me again!
🔹 Check your X account to verify the post is published.
🔹 If the tweet doesn't appear, make sure the services are running correctly and check the logs in Spring Boot.
- Log in to the UI
- Click "GO TO NEAR CONSOLE"
- Check if your tweet is recorded with a timestamp.
📌 If no logs appear, make sure your NEAR contract is deployed successfully.
🎯 Final Notes
🔹 API rate limits apply! Monitor them in X Developer Portal.
🔹 Automate your social media posts securely with XBot AI! 🚀
- POST
/api/auth/login
— Log in and receive a JWT token. - POST
/api/auth/register
— Register a new user.
- GET
/api/bot/trends
— Retrieve trending topics.
- POST
/api/bot/select-trend
— Select a trend. - GET
/api/bot/generate-tweet
— Generate a post. - POST
/api/bot/post-tweet
— Post a tweet.
- GET
/api/blockchain/logs
— View post logs stored on the blockchain.
- Frontend UI: http://localhost:5173
- H2 Database Console: http://localhost:8080/h2-console
🔹 How It Works:
1️⃣ Retrieves trending topics by country from Gemini.
2️⃣ Processes the trend and sends it to Gemini.
3️⃣ Generates on AI-powered post.
4️⃣ Publishes the post on X.
5️⃣ Logs the interaction on NEAR Testnet for transparency.
🔹 More blockchain integrations.
🔹 AI-powered trend analysis for better post engagement.
🔹 Multimedia post support (images, videos, polls).
🔹 MIT License – Open-source and free to modify.
🔹 XBot AI – your AI-powered assistant for X.
✨ Automate, publish, and analyze trends effortlessly! 🚀