homelab-brain/chatlogger
Homelab Cursor d82b6f97ef feat(chatlogger): multi-tenant + Jarvis tool integration
Phase 2 of the chatlogger feature.

Multi-tenant:
- chatlogger-bot.service -> chatlogger-bot@.service (systemd template)
- /opt/chatlogger/<instance>.env per bot, all share /opt/chatlogger/chats.db
- existing bot migrated: chatlogger-bot@arakawa.service
- adding a second group bot is now: cp arakawa.env <name>.env, edit token+chats,
  systemctl enable --now chatlogger-bot@<name>

Jarvis (hausmeister-bot) tool:
- homelab-ai-bot/tools/chatlog.py (autodiscovered by tool_loader.py)
- 4 tools: chatlog_list_chats, chatlog_recent, chatlog_search, chatlog_since
- Reads SQLite directly via sys.path += /opt/homelab-brain/chatlogger
- SYSTEM_PROMPT_EXTRA tells the LLM when to use these (Concierge, Airbnb,
  Listing, 'aktueller Stand', 'wer hat zugesagt', 'muss ich reagieren').

Tested live: hausmeister-bot loads 48 tools (44 + 4 new), all chatlog
handlers callable, returns real messages from the @arakawa_concierge_bot
recording of -1003924901022.
2026-05-01 12:13:00 +02:00
..
__init__.py feat(chatlogger): Arakawa Concierge — passive Telegram group chat logger 2026-05-01 12:03:22 +02:00
chatlogger-bot@.service feat(chatlogger): multi-tenant + Jarvis tool integration 2026-05-01 12:13:00 +02:00
chatlogger_bot.py feat(chatlogger): multi-tenant + Jarvis tool integration 2026-05-01 12:13:00 +02:00
env.example feat(chatlogger): Arakawa Concierge — passive Telegram group chat logger 2026-05-01 12:03:22 +02:00
query.py feat(chatlogger): Arakawa Concierge — passive Telegram group chat logger 2026-05-01 12:03:22 +02:00
README.md feat(chatlogger): Arakawa Concierge — passive Telegram group chat logger 2026-05-01 12:03:22 +02:00
store.py feat(chatlogger): Arakawa Concierge — passive Telegram group chat logger 2026-05-01 12:03:22 +02:00

Arakawa Concierge — Group Chat Logger

Stand-alone Telegram bot (@arakawa_concierge_bot) that silently records configured group chats into a SQLite database. Intended as the read-only data source for the Hausmeister bot (Jarvis) so it can answer questions about what was said, agreed, or left open in a managed chat.

Phase 1 (this code): capture only — no auto-replies, no LLM, no classification. Only the admin can use admin commands; in groups the bot is mute except when the admin sends /whichchat.

Files

File Purpose
chatlogger_bot.py Main bot (long-poll, message handlers, admin commands)
store.py SQLite schema + CRUD + FTS5 search
query.py CLI: recent, search, stats, chats, since, export
chatlogger-bot.service systemd unit (installed on CT 116)
env.example template for /opt/chatlogger/env (NOT committed)

Runtime layout on CT 116

/opt/homelab-brain/chatlogger/   # code (read-only via bind-mount mp1)
/opt/chatlogger/
  ├── env                        # token + chat allowlist (chmod 600, root)
  └── chats.db                   # SQLite, WAL mode
/etc/systemd/system/chatlogger-bot.service

/opt/bot-venv is shared with the hausmeister-bot (python-telegram-bot 22.6).

First-time install (on CT 116)

mkdir -p /opt/chatlogger
cp /opt/homelab-brain/chatlogger/env.example /opt/chatlogger/env
$EDITOR /opt/chatlogger/env       # paste token, set chat ids
chmod 600 /opt/chatlogger/env

cp /opt/homelab-brain/chatlogger/chatlogger-bot.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now chatlogger-bot
journalctl -u chatlogger-bot -f

Adding a new group

  1. Add @arakawa_concierge_bot to the group as a regular member (no admin needed).
  2. As admin, send /whichchat in the group → bot replies with the chat_id.
  3. Append the id to ARAKAWA_BOT_ALLOWED_CHATS in /opt/chatlogger/env (comma separated).
  4. systemctl restart chatlogger-bot.

BotFather group privacy MUST be off otherwise the bot only sees @mentions: /mybots@arakawa_concierge_botBot SettingsGroup PrivacyTurn off, then remove and re-add the bot to the group (Telegram caches the privacy flag per chat).

CLI

# Most recent 50 messages, all chats
/opt/bot-venv/bin/python /opt/homelab-brain/chatlogger/query.py recent -n 50

# Search
/opt/bot-venv/bin/python /opt/homelab-brain/chatlogger/query.py search "kaution"

# Last 24h of one chat
/opt/bot-venv/bin/python /opt/homelab-brain/chatlogger/query.py since 1440 --chat -1003924901022

# Per-chat stats
/opt/bot-venv/bin/python /opt/homelab-brain/chatlogger/query.py stats

# Export as JSONL (e.g. for handing to the Hausmeister-Bot)
/opt/bot-venv/bin/python /opt/homelab-brain/chatlogger/query.py export --chat -1003924901022 > /tmp/log.jsonl

A wrapper /usr/local/bin/chatlogger may be installed for convenience:

#!/bin/bash
exec /opt/bot-venv/bin/python /opt/homelab-brain/chatlogger/query.py "$@"

Telegram commands (admin only)

Command Where Effect
/whichchat any chat (admin) Bot replies with chat_id, type, title, allowlist status
/log_status any chat (admin) DB size, message counts per chat
/recent [N] any chat (admin) Last N messages of the current chat (or all in PM)
/search <text> any chat (admin) FTS5 search in the current chat (or all in PM)

These are the only messages the bot ever sends. Group members other than the admin get no reply at all.

Schema (SQLite)

messages (one row per Telegram message), messages_fts (FTS5 mirror), message_edits (audit log of edits). Unique key (chat_id, message_id) makes ingestion idempotent — a Telegram retry never duplicates rows.

Phase 2 (later) — Jarvis access

Add homelab-ai-bot/tools/chatlog.py with three tool functions (chatlog_recent, chatlog_search, chatlog_summary) that import chatlogger.store and read the same SQLite file directly (CT 116 sees it locally, no API needed). Wire them into llm.py routing on keywords like „Gruppe", „Airbnb", chat title, etc.