Telegram bot running server-admin tasks via Claude Agent SDK
kurigram bot with admin check by user IDs from env, per-chat Claude session resume, streaming progress, /model command for model and reasoning effort selection, and systemd deploy script. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
17
deploy/claude-tg-bot.service
Normal file
17
deploy/claude-tg-bot.service
Normal file
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Claude Server Admin Telegram Bot
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/claude-tg-bot
|
||||
EnvironmentFile=/etc/claude-tg-bot/.env
|
||||
Environment=IS_SANDBOX=1
|
||||
ExecStart=/opt/claude-tg-bot/venv/bin/python -m bot.main
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
65
deploy/install.sh
Normal file
65
deploy/install.sh
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
# Installs the Claude Server Admin Telegram Bot as a systemd service.
|
||||
# Run as root on the target Linux server, from the project root:
|
||||
# sudo bash deploy/install.sh
|
||||
set -euo pipefail
|
||||
|
||||
INSTALL_DIR=/opt/claude-tg-bot
|
||||
CONFIG_DIR=/etc/claude-tg-bot
|
||||
SERVICE_NAME=claude-tg-bot
|
||||
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "ERROR: run as root (sudo bash deploy/install.sh)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "==> Checking prerequisites"
|
||||
missing=0
|
||||
if ! command -v python3 >/dev/null; then
|
||||
echo "ERROR: python3 not found. Install it (e.g. apt install python3 python3-venv)." >&2
|
||||
missing=1
|
||||
fi
|
||||
if ! command -v node >/dev/null; then
|
||||
echo "ERROR: node not found. The Claude Agent SDK needs Node.js 18+." >&2
|
||||
echo " e.g. curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt install -y nodejs" >&2
|
||||
missing=1
|
||||
fi
|
||||
if ! command -v claude >/dev/null; then
|
||||
echo "WARNING: claude CLI not found. Install it: npm install -g @anthropic-ai/claude-code" >&2
|
||||
echo " (newer claude-agent-sdk versions bundle the CLI; if the bot fails to start, install it)" >&2
|
||||
fi
|
||||
[[ $missing -eq 0 ]] || exit 1
|
||||
|
||||
echo "==> Copying project to $INSTALL_DIR"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
cp -r "$PROJECT_DIR/bot" "$PROJECT_DIR/requirements.txt" "$INSTALL_DIR/"
|
||||
|
||||
echo "==> Creating virtualenv and installing dependencies"
|
||||
if [[ ! -d "$INSTALL_DIR/venv" ]]; then
|
||||
python3 -m venv "$INSTALL_DIR/venv"
|
||||
fi
|
||||
"$INSTALL_DIR/venv/bin/pip" install --upgrade pip -q
|
||||
"$INSTALL_DIR/venv/bin/pip" install -r "$INSTALL_DIR/requirements.txt" -q
|
||||
|
||||
echo "==> Setting up config in $CONFIG_DIR"
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
if [[ ! -f "$CONFIG_DIR/.env" ]]; then
|
||||
cp "$PROJECT_DIR/.env.example" "$CONFIG_DIR/.env"
|
||||
chmod 600 "$CONFIG_DIR/.env"
|
||||
echo ""
|
||||
echo "!! Created $CONFIG_DIR/.env from template."
|
||||
echo "!! Fill in TELEGRAM_API_ID, TELEGRAM_API_HASH, TELEGRAM_BOT_TOKEN, ADMIN_IDS,"
|
||||
echo "!! then run: systemctl restart $SERVICE_NAME"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "==> Installing systemd service"
|
||||
cp "$PROJECT_DIR/deploy/$SERVICE_NAME.service" "/etc/systemd/system/$SERVICE_NAME.service"
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now "$SERVICE_NAME"
|
||||
|
||||
echo "==> Done"
|
||||
systemctl --no-pager status "$SERVICE_NAME" || true
|
||||
echo ""
|
||||
echo "Logs: journalctl -u $SERVICE_NAME -f"
|
||||
Reference in New Issue
Block a user