An AI-powered Telegram bot for sqrDAO, developed by sqrFUND. This bot helps manage the sqrDAO community, provides information about sqrDAO and sqrFUND, and assists with various administrative tasks.
🤖 Try it now: t.me/sqrAgent_bot
This AI agent is a project by sqrFUND, providing intelligent assistance for the sqrDAO community. It leverages Google's Gemini AI to deliver context-aware responses and manage community resources effectively.
- 🤖 AI-powered responses using Google's Gemini 2.0 Flash model
- 📚 Knowledge base management
- 👥 Member management system
- 💬 Group chat support (responds only when explicitly mentioned in group chats)
- 🔍 Web search capabilities
- 💰 SQR token functions (information & balance checking)
- 📢 Mass messaging system
- 🎙️ Twitter Space summarization
- ✏️ Summary editing capabilities
- Member request system
- Member approval/rejection workflow
- Different access levels (Authorized Members and Regular Members)
- Member-only resources and commands
- Automatic group detection when bot is added/removed
- Manual group management commands
- Group tracking and persistence
- Mass messaging to groups
/start
- Start the bot and get welcome message/help
- Show help and list of available commands/about
- Learn about sqrDAO and sqrFUND/website
- Get sqrDAO's and sqrFUND's website/contact
- Get contact information/events
- View sqrDAO events/balance
- Check $SQR token balance/sqr_info
- Get information about the $SQR token/request_member
- Request to become a member/summarize_space
- Summarize an X (Twitter) Space (requires $SQR tokens)/edit_summary
- Edit a previously generated Space summary
/resources
- Access internal resources for sqrDAO Members and sqrFUND Chads
/learn
- Add information to the bot's knowledge base/learn_from_url
- Learn from a web page by providing a URL/bulk_learn
- Add multiple entries from CSV file/approve_member
- Approve a member request/reject_member
- Reject a member request/list_requests
- View pending member requests/list_members
- List all current members/mass_message
- Send a message or image to all users and groups/channels/list_groups
- List all tracked groups
The bot automatically detects and tracks groups when:
- It is added to a new group
- It receives messages from a group
- It is removed from a group
Authorized members can manage groups using the following commands:
/list_groups
- View all tracked groups
- In group and supergroup chats, the bot ignores all messages unless explicitly mentioned using
@botusername
or a direct text mention. - This ensures the bot responds only to relevant messages and avoids unwanted noise.
The /mass_message
command has been updated to:
- Send messages or images to regular members only (excluding authorized members)
- Send messages to all tracked groups with customizable prefixes
- Support for sqrDAO and Summit group filtering
- Provide detailed delivery statistics
- Show failed message attempts
- Include proper error handling and logging
- Support for both text messages and images with captions
The /summarize_space
command allows users to:
- Submit X (Twitter) Space URLs for summarization
- Process SQR token transfers
- Verify transactions within a 30-minute window
- Track download and summarization progress
- Receive formatted summaries of Space content
- Handle multiple attempts with proper error messages
- Support for both private and group chats
- Edit generated summaries using
/edit_summary
- Shorten summaries using
/shorten_summary
- Support for both text and audio summaries
- Automatic splitting of long summaries into multiple messages
- Progress tracking with attempt counts
- Proper error handling and user feedback
The bot integrates with the sqrDAO Spaces Summarization API to provide high-quality summaries of Twitter Spaces. This integration:
- Uses yt-dlp to download Twitter Spaces audio
- Leverages Google's Generative AI (Gemini) for content summarization
- Supports asynchronous processing for long Spaces
- Provides job tracking and status updates
- Handles authentication and API key management
- Supports custom prompt types for different summarization styles
- Allows editing and shortening of generated summaries
- Implements proper locking mechanisms to prevent duplicate processing
- Includes comprehensive error handling and logging
- Supports both text and audio output formats
To summarize a Twitter Space:
- Send the
/summarize_space
command followed by the Space URL and type (text/audio) - The bot will verify your SQR token balance and process the payment
- The Space will be downloaded and processed by the sqrDAO Spaces Summarization API
- You'll receive a formatted summary of the Space content
- Use
/edit_summary
to modify the generated summary if needed - Use
/shorten_summary
to get a more concise version
Example:
/summarize_space https://twitter.com/i/spaces/YOUR_SPACE_ID text
/edit_summary https://twitter.com/i/spaces/YOUR_SPACE_ID [your_edit_prompt]
/shorten_summary https://twitter.com/i/spaces/YOUR_SPACE_ID
- Text summary cost: 1000 SQR tokens
- Audio summary cost: 2000 SQR tokens
- The fee is automatically deducted from your wallet
- You must have sufficient SQR tokens in your wallet to use this feature
- Token transfers are verified on-chain before processing begins
- Transaction must be completed within 30 minutes of request
- Supports up to 3 signature attempts for failed transactions
To set up your bot on Telegram, follow these steps:
-
Open Telegram: If you haven't already, download and install the Telegram app on your device or use the web version.
-
Find BotFather: In the Telegram app, search for
@BotFather
and start a chat with it. BotFather is the official Telegram bot that helps you create and manage your bots. -
Create a New Bot:
- Type
/newbot
and send the message. - BotFather will ask you for a name for your bot. This is the display name that users will see.
- Next, you will be prompted to choose a username for your bot. The username must end with
bot
(e.g.,sqrdao_bot
).
- Type
-
Get Your Bot Token: After successfully creating your bot, BotFather will provide you with a token. This token is essential for your bot to connect to the Telegram API. It will look something like this:
123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ
-
Store Your Token: Make sure to store this token securely. You will need to add it to your
.env
file in your project directory later as follows:TELEGRAM_BOT_TOKEN=your_telegram_bot_token
To set up Google Custom Search Engine (CSE) for your bot, follow these steps:
-
Go to Google Custom Search: Visit the Google Custom Search Engine page.
-
Create a New Search Engine:
- Click on the "Add" button to create a new search engine.
- Fill in the required fields:
- Sites to Search: Enter the websites you want to include in your search engine. You can add multiple sites.
- Name: Give your search engine a name.
- Click on the "Create" button.
-
Get Your Search Engine ID:
- After creating the search engine, you will be taken to the control panel.
- Find your Search Engine ID in the control panel. You will need this ID for your bot.
-
Enable the Custom Search API:
- Go to the Google Cloud Console.
- Create a new project or select an existing project.
- Navigate to APIs & Services > Library.
- Search for "Custom Search API" and enable it for your project.
-
Create API Credentials:
- In the Google Cloud Console, go to APIs & Services > Credentials.
- Click on "Create Credentials" and select "API key".
- Copy the generated API key. You will need to add it to your
.env
file.
-
Store Your API Key and CSE ID: Add the following lines to your
.env
file:GOOGLE_API_KEY=your_google_api_key GOOGLE_CSE_ID=your_google_cse_id
- Clone the repository:
git clone https://github.com/sqrdao/sqrDAO-AI-Agent.git
cd sqrDAO-AI-Agent
- Install dependencies:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
- Create a
.env
file with all required variables:
TELEGRAM_BOT_TOKEN=your_bot_token
GEMINI_API_KEY=your_gemini_api_key
GOOGLE_API_KEY=your_google_api_key
GOOGLE_CSE_ID=your_google_cse_id
SOLANA_RPC_URL=your_solana_rpc_url
SPACES_API_URL=https://spaces.sqrfund.ai/api
SPACES_API_KEY=your_spaces_api_key
SQR_FUND_API_KEY=your_sqr_fund_api_key
- Run the bot:
python bot.py
To view the logs for your bot running on a Virtual Machine (VM), you can use the journalctl
command. This command allows you to see logs in real-time.
-
Access Your VM: Use SSH or a remote desktop connection to log into your VM.
-
Use the
journalctl
Command: To view logs for your specific service, run the following command:journalctl -u my_service -f
Replace
my_service
with the actual name of your service. -
Real-Time Log Monitoring: The
-f
option will follow the logs, meaning you will see new log entries as they are written. -
Exit the Log View: To stop following the logs, press
Ctrl + C
.
Here's a complete example command to follow logs for a service named sqrdao-bot
:
journalctl -u sqrdao-bot -f
This command will display the logs for sqrdao-bot
and update in real-time as new log entries are added.
- Powered by Google's Gemini 2.0 Flash model
- Context-aware responses using conversation history
- Markdown formatting support
- HTML formatting for Telegram messages
- Enhanced response formatting with HTML tags
- Works in both private chats and group chats
- Responds to mentions in group chats
- Maintains context separately for each user
- Handles group chat permissions appropriately
- Check Solana wallet balances using wallet addresses
- Support for .sol DID resolution using SNS.ID
- Works in both private and group chats
- Automatic wallet address validation
- Real-time balance updates
- User-friendly error messages
- Support for checking own balance in private chat
- Support for checking specific wallet balances
- Support for checking balances using .sol DIDs
- SQLite database for storing information
- Topic-based knowledge storage
- Accessible through
/learn
and/bulk_learn
commands - CSV template for bulk learning
- Used to enhance bot responses
- Two-tier access system:
- Regular members: Access to resources
- Authorized members: Full access including knowledge base management and member approval
- Member request system with approval workflow
- User ID and username-based verification
- Members stored in knowledge base with user IDs
- Automatic command menu updates for members
- Stores conversation history in SQLite
- Uses previous conversations for context
- Enhances response relevancy
- Google Custom Search integration
- Web content extraction
- URL processing and content summarization
- Automatic delimiter detection for CSV files
- Enhanced error handling and reporting
- Works in both private and group chats
- Respects group chat permissions
- Provides formatted responses suitable for group discussions
- CSV file support for adding multiple entries
- Multiple delimiter support (comma, semicolon, tab, pipe)
- Template file with examples
- Error handling and reporting
For production deployment:
- Set up the environment and dependencies
- Configure systemd service (Linux):
sudo nano /etc/systemd/system/sqrdao-bot.service
Example service file:
[Unit]
Description=sqrDAO AI Agent
After=network.target
[Service]
Type=simple
User=your_user
WorkingDirectory=/path/to/sqrDAO-AI-Agent
Environment=PYTHONPATH=/path/to/sqrDAO-AI-Agent
ExecStart=/path/to/venv/bin/python bot.py
Restart=always
[Install]
WantedBy=multi-user.target
- Start the service:
sudo systemctl enable sqrdao-bot
sudo systemctl start sqrdao-bot
-
Update the code:
- Navigate to your project directory:
cd /path/to/sqrDAO-AI-Agent
- Pull the latest changes from the repository:
git pull origin main # or the appropriate branch name
-
Restart the service:
sudo systemctl restart sqrdao-bot
Core dependencies:
beautifulsoup4
- Web scrapinggoogle-generativeai
- Gemini AI integrationgoogle-api-python-client
- Google Custom Searchpython-dotenv
- Environment variablespython-telegram-bot
- Telegram bot functionalityrequests
- HTTP requeststrafilatura
- Web content extractiongoogle-auth
- Google authenticationgoogle-auth-httplib2
- Google authentication for HTTPhttplib2
- HTTP client librarysoupsieve
- Soup parsing libraryurllib3
- HTTP librarysolana
- Solana blockchain librarysolders
- Solana data structuresbase58
- Base58 encoding/decodingyt-dlp
- YouTube-DL fork for media downloading
For a complete list with versions, see requirements.txt
.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is open-source and available under the following terms:
- ✅ Public, non-commercial use
- ✅ Educational purposes
- ✅ Research and development
- ✅ Personal projects
- ✅ Community building
- ✅ Non-profit organizations
- ❌ Commercial use without explicit permission
- ❌ Token launches or cryptocurrency offerings
- ❌ Financial products or services
- ❌ Rebranding without attribution
- ❌ Closed-source modifications
- Must maintain original copyright notices
- Must credit sqrFUND as the original creator
- Must link to the original repository
Copyright © 2024 sqrFUND. For commercial licensing inquiries, please contact [email protected].
Get in touch with us:
- 📧 Email: [email protected]
- 🐦 X (formerly Twitter): @sqrfund_ai
- 💬 Telegram channel: @sqrfund_ai
- 🌐 Website: sqrfund.ai
Join our community channels for updates and discussions!