Telegram bridge for Kotaemon with production-focused UX: document selection, clean citations, cited-page PDF delivery, PNG album, ACL, local storage ingest and systemd deploy.
/startnow opens file picker immediately (no command wall)- Dedicated
/cmdhelp command - Cited-pages one-file PDF flow (
📄 PDF откуда Инфо) 🧩 PNG albumaction (media-group in one message)citsrcsends quote in image caption (single message per image)- Local storage ingest pipeline (
/ingest) with persistent page artifacts - Better Telegram timeout handling, retries, and verbose diagnostics
- Optional HTTP proxy via systemd drop-in
flowchart LR
TG[Telegram User] --> BOT[Kotaemon Telegram Bridge]
BOT --> KOT[Kotaemon / Gradio API]
BOT --> DB[(SQLite state.db\nACL + user state)]
BOT --> ST[(storage/\nincoming + rendered pages + bundles)]
ST --> PDF[One-file cited PDF]
ST --> PNG[PNG album by cited pages]
BOT -->|sendDocument / sendMediaGroup| TG
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
# edit .env
python bot.pychmod +x deploy.sh
./deploy.sh <linux-user>Service logs:
journalctl -u kotaemon-telegram-bridge -f/start- Select files in
/files - Ask a question (
/ask ...or plain text) - Use inline actions:
📄 PDF откуда Инфо— one-file cited-pages PDF🧩 PNG альбом— cited PNG pages as one album📎 Цитаты + PDF— quote + matching page image
/start— greeting + immediate file picker/cmd— full command help/files— inline file picker/use <name|id>— select file by name/id/clearuse— clear selected files/selected— show selected file ids/ask <question>— ask Kotaemon/citations— cleaned citations/sources— cited-pages PDF sources flow/citsrc— citation + matching page image/mindmap— mindmap image/relogin— relogin to Kotaemon
Admin:
/adduser <telegram_id>/deluser <telegram_id>/users/prepdf <pdf_url_or_path>/prepdfid <file_id>/ingest [file_id|name|path]
Put PDFs into:
storage/incoming/<file_id>.pdforstorage/incoming/<name>.pdf
Then run (admin):
/ingest <file_id|name|path>for one file/ingestto process all PDFs instorage/incoming
Generated artifacts:
storage/rendered/pdf_pages/<key>/page-XXXX.pdfstorage/rendered/png_pages/<key>/page-XXXX.pngstorage/rendered/bundles/<key>.pdf
How it works:
- bot resolves selected
file_idagainst local index - extracts cited pages
- builds one compact PDF from cited pages (up to 10)
- sends one file (with background retry fallback)
/etc/systemd/system/kotaemon-telegram-bridge.service.d/proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7080"
Environment="HTTPS_PROXY=http://127.0.0.1:7080"
Environment="NO_PROXY=localhost,127.0.0.1,kotaemon.example.com,.example.com"Apply:
sudo systemctl daemon-reload
sudo systemctl restart kotaemon-telegram-bridge
sudo systemctl show kotaemon-telegram-bridge --property=Environment --no-pager- Keep
.envprivate - Use strict whitelist
- Prefer dedicated Kotaemon account instead of
admin
Apache-2.0