https://github.com/vero-git-hub/xbot-ai
Xbot AI is an AI-powered assistant for X (formerly Twitter) that fetches Google Trends, generates posts via Gemini AI, and logs interactions on the NEAR blockchain. Users can interact with the bot by mentioning @xbot_ai_.
https://github.com/vero-git-hub/xbot-ai
ai ai-assistant blockchain flask gemini-api google-trends java near oauth python react spring-boot twitter twitter-bot typescript x-api x-bot
Last synced: about 2 months ago
JSON representation
Xbot AI is an AI-powered assistant for X (formerly Twitter) that fetches Google Trends, generates posts via Gemini AI, and logs interactions on the NEAR blockchain. Users can interact with the bot by mentioning @xbot_ai_.
- Host: GitHub
- URL: https://github.com/vero-git-hub/xbot-ai
- Owner: vero-git-hub
- License: mit
- Created: 2025-02-09T18:32:29.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2025-02-25T18:56:58.000Z (3 months ago)
- Last Synced: 2025-02-25T19:38:52.865Z (3 months ago)
- Topics: ai, ai-assistant, blockchain, flask, gemini-api, google-trends, java, near, oauth, python, react, spring-boot, twitter, twitter-bot, typescript, x-api, x-bot
- Language: Java
- Homepage: https://devpost.com/software/xbot-ai
- Size: 595 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π€ XBot AI
**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.
## β¨ Features
- **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](https://devpost.com/software/xbot-ai).
## βοΈ Architecture
### **1οΈβ£ Core Technologies**
| **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 |### **2οΈβ£ Blockchain & Smart Contracts**
| **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 |### **3οΈβ£ Data Fetching**
| **API** | **Plan** | **Usage** |
|--------|----------|---------------------------------------------|
| **X API** | Free | X API v2 (OAuth 1.0a via ScribeJava) |### **4οΈβ£ X Developer Platform**
| **Component** | **Usage** |
|--------------|-------------------------------------------------|
| **X Developer Platform** | Two developer accounts for XBot AI (user & bot) |### **5οΈβ£ X API Endpoints**
| **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 |### **6οΈβ£ Databases & Storage**
| **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 |### **7οΈβ£ AI Integration**
| **Service** | **Model** - | **Usage** |
|---------------------------------------|------------------|-------------------------------|
| **Gemini API (Google Cloud Console)** | gemini-1.5-flash | Get trends & generate post |## π₯ Installation
### 1οΈβ£ Clone the repository:
```bash
git clone https://github.com/vero-git-hub/xbot-ai.git
cd xbot-ai
```### 2οΈβ£Start the Project (2 services need to be running):
β **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:
##### πΉ Obtain a Google Cloud API Key
1. Create an account on [Google Cloud](https://cloud.google.com/).
2. Create a new project in **Google Cloud Console**
3. Enable **Gemini API**
4. Generate an **API Key**:
1. Go to **API & Services > Credentials**
2. Click **"Create Credentials" > "API key"**
5. Add the API key to ```src/main/resources/application-local.properties```:```bash
google.cloud.api.key=your_google_cloud_api_key
```##### πΉ Generate jwt.secret
On **Windows (PowerShell):**
```bash
[Convert]::ToBase64String((1..64 | ForEach-Object {Get-Random -Maximum 256}))
```On **Linux/macOS**:
```bash
openssl rand -base64 64
```Add the **generated secret key** to ```src/main/resources/application.properties:```
```bash
jwt.secret=your_jwt_secret
```##### πΉ Start the Spring Boot service:
```bash
mvn spring-boot:run
```β **Run frontend service, start Node.js (React UI):**
```bash
cd frontend
npm install
npm run dev
```---
### 3οΈβ£ Configure X accounts via UI
1. Open the UI interface:π Go to http://localhost:5173/
2. 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#### β Connect your X account
πΉ Click **"CONNECT YOUR ACCOUNT X"**
Fill in the fields with your credentials. How to find them?
1. **Log in or sign up** on [X Developer Platform](https://developer.x.com/en)
2. Go to [Developer Dashboard](https://developer.twitter.com/en/portal/dashboard)
3. In the left sidebar, click **Projects & Apps**, and select your project (default one)
4. 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)*
5. Click **Save**
6. 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 |7. Get the User ID:
* Retrieve the **Bearer Token** from the **Keys and tokens** tab
* Use **Postman** or another API tool to make a request:
```bash
GET https://api.twitter.com/2/users/by/username/YOUR_USERNAME
```* Add the header:
```bash
Authorization: Bearer YOUR_BEARER_TOKEN
```
* The response will contain an ```id``` field. Use this as **User ID** in the UI.9. Click **Save Settings β Back to Dashboard**
---
#### β Connect bot X account
πΉ 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```).
---
### 4οΈβ£Connect NEAR for blockchain logging
1. **Install NEAR CLI:**
```bash
npm install -g near-cli
near --version
```2. **Create a MyNearWallet account on the Testnet:**
```bash
near login --networkId testnet
```This will store your credentials locally:
```C:\Users\\.near-credentials\testnet```
3. **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:
```bash
cd blockchain
near deploy [your-name].testnet ubuntu/near-logger-contract.wasm
npm install near-api-js
```---
### 5οΈβ£Test the Bot Interaction in X
#### π’ Step 1: Trigger the bot with a mention
1. Open your X account and post:
```bash
@[your_bot] trends
```2. Set **Who can reply? β Only accounts you mention can reply** β Post
3. Uncomment line 88:
```bash
src/main/java/org/example/xbotai/service/core/impl/SocialMediaBotMentionService.java
``````bash
@Scheduled(fixedDelay = 900000)
```This line enables bot mention tracking.
βοΈ API Free Plan has limitations. You can see them in [X Developer Platform](https://developer.twitter.com/en/portal/products) It's recommended to enable it only when everything is set up. βοΈ
4. Start both servers:
```bash
mvn spring-boot:run
npm run dev
```5. Check if the bot responds:
```bash
Enter your country to search for trends (United States, Canada)
```#### π’ Step 2: Provide a country for trend search
1. Reply:
```bash
country United States
```2. **Restart the Java server** (to activate an additional endpoint to search for bot mentions):
```bash
mvn spring-boot:run
```3. The bot will fetch trends and respond:
```bash
Trend1, Trend2, Trend3
```#### π’ Step 3: Select a trend for AI post generation
1. Reply with a trend:
```bash
trend [selected-trend]
```2. The bot will generate a post and publish it **after 15 minutes.**
#### π’ Step 4: Bot confirms post publication
β If everything works correctly, you will see:
```bash
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.
---
### 6οΈβ£Test the Blockchain Interaction via UI
1. **Log in to the UI**
2. Click **"GO TO NEAR CONSOLE"**
3. 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!** π
## π‘ API Endpoints
### π Authentication
* POST ```/api/auth/login``` β Log in and receive a JWT token.
* POST ```/api/auth/register``` β Register a new user.### π Fetching Trends Data
* GET ```/api/bot/trends``` β Retrieve trending topics.### π Post Generation & AI
* POST ```/api/bot/select-trend``` β Select a trend.
* GET ```/api/bot/generate-tweet``` β Generate a post.
* POST ```/api/bot/post-tweet``` β Post a tweet.### π Blockchain Logging
* GET ```/api/blockchain/logs``` β View post logs stored on the blockchain.
### πͺͺ Local Links
* Frontend UI: http://localhost:5173
* H2 Database Console: http://localhost:8080/h2-console## π§ Gemini AI Integration
πΉ **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.
## π Future Improvements
πΉ More blockchain integrations.
πΉ AI-powered trend analysis for better post engagement.
πΉ Multimedia post support (images, videos, polls).
## π License
πΉ **MIT License** β Open-source and free to modify.
πΉ **XBot AI β your AI-powered assistant for X**.
β¨ Automate, publish, and analyze trends effortlessly! π