๐ฆ ClawHub
Telegram CS Agent
by @youziyouzishu
Deploy and manage a Telegram customer service bot powered by Claude + RAG. Use when setting up a new CS bot, adding knowledge base docs, managing the bot lif...
TERMINAL
clawhub install tg-cs-agent๐ About This Skill
name: tg-cs-agent description: Deploy and manage a Telegram customer service bot powered by Claude + RAG. Use when setting up a new CS bot, adding knowledge base docs, managing the bot lifecycle (start/stop/restart), or troubleshooting bot issues. Triggers on "customer service bot", "CS bot", "ๅฎขๆๆบๅจไบบ", "telegram bot", "knowledge base".
Telegram Customer Service Agent
RAG-powered Telegram customer service bot using Claude + Telethon + ChromaDB.
Architecture
Prerequisites
tgctl-telethon login or manual auth)Setup New Bot
1. Create project
mkdir -p ~/tg-cs-bot && cd ~/tg-cs-bot
cp -r /scripts/*.py .
pip install anthropic chromadb sentence-transformers python-dotenv telethon
2. Configure environment
Create .env:
ANTHROPIC_API_KEY=
ANTHROPIC_BASE_URL=https://api.anthropic.com
TELEGRAM_API_ID=
TELEGRAM_API_HASH=
TELEGRAM_PROFILE=default
MODEL=claude-sonnet-4-20250514
KNOWLEDGE_DIR=docs
MAX_HISTORY=20
HANDOFF_CHAT_ID=
3. Add knowledge base
Put markdown files in docs/ directory. The bot splits by ## headers and vectorizes with paraphrase-multilingual-MiniLM-L12-v2 for multilingual support.
4. Login to Telegram (first time only)
python3 -c "
from telethon import TelegramClient
import asyncio
async def login():
c = TelegramClient('~/.tgctl-telethon/default/session', API_ID, 'API_HASH')
await c.start()
print('Logged in:', (await c.get_me()).first_name)
asyncio.run(login())
"
5. Run
python3 main.py
Managing the Bot
python3 main.py (or use the start.sh script).md files in docs/, restart bot/clear/humanCustomization
System Prompt
Edit config.py โ __post_init__ โ self.system_prompt to change:
Embedding Model
In knowledge.py, change model_name for different language support:
paraphrase-multilingual-MiniLM-L12-v2 โ multilingual (recommended)all-MiniLM-L6-v2 โ English only, fastershibing624/text2vec-base-chinese โ Chinese optimizedHandoff Behavior
The bot adds [HANDOFF] to responses when it can't help. This triggers:
1. Notification to HANDOFF_CHAT_ID with user info
2. A message to the user that human support is coming
File Structure
tg-cs-bot/
โโโ main.py # Entry point, message routing
โโโ config.py # Config + system prompt
โโโ agent.py # Claude RAG agent
โโโ knowledge.py # ChromaDB knowledge base
โโโ telegram_client.py # Telethon wrapper
โโโ .env # Secrets (not committed)
โโโ docs/ # Knowledge base markdown files
โ โโโ platform.md
โ โโโ faq.md
โ โโโ ...
โโโ requirements.txt
Troubleshooting
session.session-journal, rebuild session with sqlite dump/restore[READY] Listening for messages... in logs, verify Telegram connectionโ๏ธ Configuration
tgctl-telethon login or manual auth)๐ Tips & Best Practices
session.session-journal, rebuild session with sqlite dump/restore[READY] Listening for messages... in logs, verify Telegram connection