cv-2026/scripts/telegram-mcp.sh

37 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Launch the telegram-mcp server for one account, reading API creds and the
# session string from the project .env. Used by .mcp.json so that NO secrets
# are hardcoded in the committed config.
#
# Usage (from .mcp.json):
# bash scripts/telegram-mcp.sh usulsu # main account -> TELEGRAM_SESSION_STRING
# bash scripts/telegram-mcp.sh helper # samuishechka -> TELEGRAM_SESSION_STRING_HELPER
#
# The telegram-mcp binary path can be overridden with TELEGRAM_MCP_BIN.
set -euo pipefail
ACCOUNT="${1:?usage: telegram-mcp.sh <usulsu|helper>}"
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
BIN="${TELEGRAM_MCP_BIN:-/home/usul/workspace/projects/my-utils/telegram/.venv/bin/telegram-mcp}"
[ -f "$PROJECT_ROOT/.env" ] || { echo "missing $PROJECT_ROOT/.env" >&2; exit 1; }
set -a; . "$PROJECT_ROOT/.env"; set +a
case "$ACCOUNT" in
usulsu) export TELEGRAM_SESSION_STRING="${TELEGRAM_SESSION_STRING:-}" ;;
helper) export TELEGRAM_SESSION_STRING="${TELEGRAM_SESSION_STRING_HELPER:-}" ;;
*) echo "account must be 'usulsu' or 'helper'" >&2; exit 1 ;;
esac
if [ -z "${TELEGRAM_API_ID:-}" ] || [ -z "${TELEGRAM_API_HASH:-}" ]; then
echo "TELEGRAM_API_ID / TELEGRAM_API_HASH missing in $PROJECT_ROOT/.env" >&2
exit 1
fi
if [ -z "${TELEGRAM_SESSION_STRING:-}" ]; then
echo "session string for '$ACCOUNT' is empty in .env — regenerate it with:" >&2
echo " pnpm tg:session:$ACCOUNT" >&2
exit 1
fi
exec "$BIN"