A powerful Rocket Chat bot that integrates with CustomGPT's API to provide AI-powered responses with built-in rate limiting, session management, and advanced features.
Get you CustomGPT.ai RAG API key here, needed to use this integration.
More information on GitHub - https://github.com/Poll-The-People/customgpt-integrations
Features
- 🤖 AI-Powered Responses: Leverages CustomGPT's knowledge base for intelligent answers
- 🔒 Security: Built-in rate limiting, user blocking, and message validation
- 💬 Conversation Management: Maintains context across messages with session handling
- 📚 Citation Support: Includes sources and references in responses
- 🎯 Starter Questions: Contextual conversation starters for better engagement
- 🧵 Thread Support: Maintains conversation context in threads
- 📊 Usage Analytics: Track bot usage and performance metrics
- 🌐 Multi-language: Support for multiple languages
- ⚡ Quick Actions: Enhanced user interactions with follow-up suggestions
Prerequisites
- Python 3.8 or higher
- Rocket Chat server (self-hosted or cloud)
- CustomGPT API key and project ID
- Bot user account in Rocket Chat
Installation
- Clone the repository:
git clone <repository-url>
cd "Rocket Chat Bot"- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Configure environment:
cp .env.example .env
# Edit .env with your configurationConfiguration
Required Settings
| Variable | Description | Example |
|---|---|---|
ROCKET_CHAT_URL | Your Rocket Chat server URL | https://chat.example.com |
ROCKET_CHAT_USER | Bot username | customgpt-bot |
ROCKET_CHAT_PASSWORD | Bot password | secure-password |
CUSTOMGPT_API_KEY | Your CustomGPT API key | cgpt_... |
CUSTOMGPT_PROJECT_ID | Your CustomGPT project/agent ID | 12345 |
Optional Settings
See .env.example for all available configuration options including rate limiting, security, and feature flags.
Creating a Bot User in Rocket Chat
- Login as admin to your Rocket Chat instance
- Navigate to Administration → Users
- Click "New" to create a new user
- Configure:
- Username:
customgpt-bot(or your preference) - Email:
[email protected] - Password: Set a secure password
- Roles: Add "bot" role
- Username:
- Save the user
- Get bot credentials:
- Username and password for
.env - Or get auth token from user settings
- Username and password for
Running the Bot
Local Development
python bot.pyUsing Enhanced Features
python enhanced_bot.pyProduction with Process Manager
Using systemd:
sudo cp rocketchat-bot.service /etc/systemd/system/
sudo systemctl enable rocketchat-bot
sudo systemctl start rocketchat-botUsing PM2:
pm2 start bot.py --name rocketchat-bot --interpreter python3
pm2 save
pm2 startupDeployment Options
1. Self-Hosted Server
Using Docker:
docker build -t rocketchat-customgpt-bot .
docker run -d --env-file .env --name customgpt-bot rocketchat-customgpt-botUsing Docker Compose:
docker-compose up -d2. Free Hosting Providers
Railway.app
- Fork this repository
- Connect Railway to your GitHub
- Create new project from repository
- Add environment variables
- Deploy
Render.com
- Create new Web Service
- Connect GitHub repository
- Build command:
pip install -r requirements.txt - Start command:
python bot.py - Add environment variables
Fly.io
fly auth login
fly launch
fly secrets set CUSTOMGPT_API_KEY=your_key
fly deployGoogle Cloud Run
gcloud run deploy rocketchat-bot \
--source . \
--platform managed \
--region us-central1 \
--set-env-vars-from-file .env.yaml3. VPS Deployment
- Setup server (Ubuntu/Debian):
sudo apt update
sudo apt install python3 python3-pip python3-venv- Deploy bot:
git clone <repository>
cd "Rocket Chat Bot"
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt- Run with systemd (see rocketchat-bot.service)
Usage
Basic Commands
@bot help- Show help message@bot start- Show starter questions@bot clear- Clear conversation context@bot stats- Show usage statistics@bot quota- Check remaining quota
Asking Questions
Simply mention the bot or send a direct message:
@bot What is machine learning?@customgpt-bot How do I create a REST API?- In DM:
Tell me about cloud computing
Using Threads
Reply to a bot message to continue the conversation in a thread while maintaining context.
Advanced Features
Rate Limiting
The bot includes sophisticated rate limiting:
- Global limit: 10 requests per minute (configurable)
- Per-user limit: 5 requests per minute (configurable)
- API limit checking: Monitors CustomGPT API usage
Session Management
- Sessions timeout after 1 hour of inactivity
- Context is maintained within sessions
- Automatic cleanup of expired sessions
Security Features
- User blocking capability
- Channel restrictions
- Message length validation
- Input sanitization
Monitoring
Track bot performance with built-in analytics:
- Request counts
- Response times
- Error rates
- User engagement
Troubleshooting
Bot not responding
- Check bot is online in Rocket Chat
- Verify bot has permissions in channel
- Check logs for errors
- Ensure proper mention format
Authentication errors
- Verify Rocket Chat credentials
- Check CustomGPT API key
- Ensure bot user has correct roles
Rate limit errors
- Check rate limit configuration
- Monitor API usage
- Adjust limits as needed
Google Apps Script Alternative
For lightweight deployments, see google-apps-script/ directory for a GAS implementation that:
- Runs on Google's infrastructure (free)
- No server management required
- Limited to webhook-based responses
- Best for low-volume usage
Development
Project Structure
Rocket Chat Bot/
├── bot.py # Main bot implementation
├── enhanced_bot.py # Enhanced features
├── config.py # Configuration management
├── customgpt_client.py # CustomGPT API client
├── rate_limiter.py # Rate limiting logic
├── conversation_manager.py # Session management
├── requirements.txt # Dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
└── README.md # Documentation
Adding New Features
- Extend
EnhancedRocketChatBotclass - Add configuration options to
Config - Update command patterns
- Add tests
Contributing
- Fork the repository
- Create feature branch
- Commit changes
- Submit pull request
License
MIT License - see LICENSE file for details
Support
CustomGPT Links
- CustomGPT Landing Page
- Live Demo
- CustomGPT Starter Kit
- CustomGPT Integrations
- API Documentation
- Postman Collection
- MCP Documentation
- Office Hours
- YouTube Channel
Platform Documentation
- Rocket Chat API: docs.rocket.chat/reference/api
Support Channels
- Issues: Create an issue in the repository
