A Telegram/Bale bot based on OpenClaw that enables conversations with various AI models.
- Features
- Prerequisites
- Installation & Setup
- Configuration
- Bot Commands
- Thinking Levels
- File Structure
- How It Works
- Models Cache
- Limitations
- Security Notes
- Sample Conversation
- License
- Multi-Model Support: Choose from various OpenAI and other provider models
- Chat History Management: Save and retrieve previous conversations
- Thinking Level Control: Adjust model reasoning depth (light, medium, extra, high, max)
- Message Deletion: Delete sent messages in Bale for privacy
- Token Monitoring: Graphical display of remaining token usage
- Persistent Storage: Maintain user state even after bot restart
- Models Caching: Reduce repeated requests to OpenClaw server
- Python 3.8 or higher
- Access to OpenClaw service (running on
http://127.0.0.1:18789) - Bale bot token (get from @BotFather or Bale equivalent)
- Python libraries (listed in
requirements.txt)
git clone <repository-url>
cd <project-directory>pip install -r requirements.txtEdit config.py and add your bot token:
BALE_TOKEN="YOUR_BOT_TOKEN_HERE"
OPENCLAW_URL="http://127.0.0.1:18789"
⚠️ Security Warning: Never commitconfig.pyto public GitHub repositories.
python main.py| Variable | Description | Default |
|---|---|---|
BALE_TOKEN |
Bale bot token | - |
OPENCLAW_URL |
OpenClaw server URL | http://127.0.0.1:18789 |
MAX_HISTORY_PER_USER |
Max chats stored per user | 30 |
MAX_RECENT_CHATS_SHOWN |
Max chats shown in list | 8 |
MODELS_CACHE_TTL_SECONDS |
Models cache TTL (seconds) | 120 |
MAX_MODEL_LIST |
Max models displayed | 12 |
| Command | Description | Example |
|---|---|---|
/start |
Start bot and show welcome message | /start |
/help |
Show full command list | /help |
/newchat or /new |
Create new chat and archive current one | /newchat |
/end or /exit |
Stop conversation and save to history | /end |
/recentchats |
Show recent chat history | /recentchats |
/continuechat <index> |
Continue a chat from history | /continuechat 2 |
/clear |
Delete all chat messages in Bale + reset history | /clear |
/deletehistory <all|index> |
Delete one or all history items | /deletehistory all |
/models |
Show OpenAI models list | /models |
/models all |
Show all available models | /models all |
/models <index> |
Select model by number | /models 3 |
/models <model_id> |
Select model directly by ID | /models openai/gpt-4 |
/model |
Show current model | /model |
/reasoning or /thinking |
Show current thinking level | /reasoning |
/reasoning <level> |
Set thinking level | /reasoning medium |
/remainingusage |
Show remaining tokens graphically | /remainingusage |
| Value | Display | Description |
|---|---|---|
off |
Off | Disable thinking |
minimal |
Minimal | Minimum thinking |
light or low |
light | Light thinking |
medium or med |
medium | Medium thinking |
high |
high | High thinking |
extra or xhigh |
extra | Extra high thinking |
max |
max | Maximum thinking |
/reasoning light # Light thinking
/reasoning medium # Medium thinking
/reasoning extra # Extra high thinking
/reasoning max # Maximum thinking
/reasoning off # Disable thinking
.
├── main.py # Main bot code
├── config.py # Configuration file (tokens & URLs)
├── requirements.txt # Python dependencies
├── history.json # Persistent user state storage
└── README.md # This readme file
- Start: User sends
/start - Select Model: User chooses model via
/models - Set Thinking: User adjusts thinking level with
/reasoning - Send Message: User sends their message
- Processing: Bot sends message to OpenClaw and receives response
- Storage: User and bot messages are saved in
history.json - End: User ends chat with
/endor/newchat
- User state is maintained in memory (
user_states) - State is periodically saved to
history.jsonand on important changes - On bot restart, states are restored from the file
To reduce repeated requests to OpenClaw server, models are cached:
- TTL: 120 seconds (configurable via
MODELS_CACHE_TTL_SECONDS) - Cache Keys:
openai: OpenAI provider modelsall: All available models
- Requires running OpenClaw server
- Maximum 30 recent chats stored per user
- Maximum 12 models displayed in list
- Message deletion in Bale may not always succeed (depends on API)
- Protect Token: Add
config.pyto.gitignore - No Git Upload: Never upload tokens to public repositories
- Use Environment Variables: In production, use environment variables
- Restrict Access: Limit access to OpenClaw server
config.py
history.json
__pycache__/
*.pyc
.envUser: /start
Bot: 👋 Hello! AI Bot is ready.
User: /models
Bot: 📡 OpenAI Models:
1. ● openai/gpt-4
2. ● openai/gpt-3.5-turbo ✅
3. ○ openai/gpt-3.5
User: /models 1
Bot: ✅ Current model set to: openai/gpt-4
User: /reasoning medium
Bot: ✅ thinking set to medium.
User: What is the capital of Iran?
Bot: The capital of Iran is Tehran.
User: /end
Bot: Conversation saved.
This project is published without a specific license. For commercial use or distribution, please contact the developer.
For bug reports or feature requests, please create an issue or contact the developer.
Developed with ❤️ for the Bale platform