Telegram Knowledge-Base Bot
Current Status
The MVP was deployed. In a Telegram group, a user could mention the bot with a question; the bot retrieved relevant knowledge-base material and generated an answer with an LLM. Mentioning it without a question returned site navigation.
Deployment
Pushing to main triggered GitHub Actions to:
- Upload knowledge-base Markdown to
/srv/knowledge_base/. - Upload
bot/to/srv/kb_bot/. - Write
/srv/kb_bot/bot/.env. - Rebuild the complete RAG vector index with
python3 retriever.py. - Restart the
kb_botsystemd service. - Add the Nginx location idempotently on the first deployment.
Production secrets were stored under GitHub Actions → Settings → Environments → prod → Secrets.
Environment Variables
| Variable | Purpose |
|---|---|
TELEGRAM_BOT_TOKEN | Token issued by BotFather |
BOT_USERNAME | Bot username without @, used to filter group mentions |
COMPATIBLE_BASE_URL | Base URL for an LLM-compatible API |
COMPATIBLE_API_KEY | API key for that endpoint |
OPENROUTER_API_KEY | OpenRouter key used for embeddings |
KB_PATH | Markdown directory, default /srv/knowledge_base |
INDEX_PATH | ChromaDB index directory, default /srv/kb_index |
GITHUB_TOKEN | Fine-grained read-only token for private repository commits in /recent |
Using the Bot
In a group, mention the bot and include a question, for example @my_kb_bot What is RAG?. A mention without a question opens navigation. In a private chat, send the question directly.
| Command | Behavior |
|---|---|
/start, /help | Feature introduction and usage |
/nav | Site navigation with page links |
/site | Site entry points |
/categories | Browse knowledge-base categories and articles |
/today | Current date |
/status | Number of loaded documents |
/recent | Summarize recent GitHub commits and pending work, then suggest next steps |
/save | Run knowledge-capture steps 1–3 on the current session and preview a write decision |
/save <text> | Capture supplied text from step 2 onward and preview a write decision |
Session Isolation
Conversation history was keyed by {chat_id}:{user_id}:{session_key}. The chat ID identified a group or private chat, the user ID isolated participants, and the session key combined the date with a sequence number. Thirty minutes of inactivity started a new session. For example, two users in the same group had different histories, and one user's later session also had a different key.
Limits and Follow-Up Work
- Session memory was added with a seven-day Redis TTL.
- Keyword matching was replaced with RAG vector retrieval.
/savesupported extraction, routing, and a preview of the write decision. Confirmation and the actual write step were still pending.- A hard-coded
chat_idallowlist restricted which groups could use the bot. - Messages from any bot account were ignored to prevent loops between bots.