Single-process Python app that: - Runs a Telegram bot in a group chat, logging all messages/files to libsql - Exposes send_message, pull_updates, queue_status MCP tools over HTTP - Downloads and stores file attachments with Telegram file_id + local path - Accessible via NetBird mesh at mgmt.mg:8321 (no auth needed) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""Configuration loader for MCP Bridge."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
CREDENTIALS_FILE = BASE_DIR / "credentials"
|
|
DB_PATH = BASE_DIR / "data" / "bridge.db"
|
|
MEDIA_DIR = BASE_DIR / "media"
|
|
|
|
# MCP server settings
|
|
MCP_HOST = "0.0.0.0"
|
|
MCP_PORT = 8321
|
|
|
|
|
|
def load_credentials() -> dict[str, str]:
|
|
"""Load credentials from KEY=VALUE file."""
|
|
config = {}
|
|
if CREDENTIALS_FILE.exists():
|
|
with open(CREDENTIALS_FILE) as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if "=" in line and not line.startswith("#"):
|
|
key, value = line.split("=", 1)
|
|
config[key.strip()] = value.strip()
|
|
return config
|
|
|
|
|
|
def get_bot_token() -> str:
|
|
creds = load_credentials()
|
|
token = creds.get("MCP_BOT_TOKEN", "")
|
|
if not token:
|
|
raise RuntimeError("MCP_BOT_TOKEN not set in credentials file")
|
|
return token
|
|
|
|
|
|
def get_group_chat_id() -> int:
|
|
creds = load_credentials()
|
|
chat_id = creds.get("GROUP_CHAT_ID", "")
|
|
if not chat_id:
|
|
raise RuntimeError("GROUP_CHAT_ID not set in credentials file")
|
|
return int(chat_id)
|
|
|
|
|
|
def get_homelab_bot_id() -> int | None:
|
|
"""Optional: ID of the existing homelab bot for sender_type classification."""
|
|
creds = load_credentials()
|
|
bot_id = creds.get("HOMELAB_BOT_ID", "")
|
|
return int(bot_id) if bot_id else None
|