-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·200 lines (179 loc) · 6.61 KB
/
setup.sh
File metadata and controls
executable file
·200 lines (179 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# Copyright (c) 2026 Nardo. AGPL-3.0 — see LICENSE
# Interactive setup for telegram-claude-bot-template.
# Run once after cloning: ./setup.sh
set -e
echo "========================================"
echo " telegram-claude-bot-template setup"
echo "========================================"
echo ""
# ── 1. Check Python ──────────────────────────────────────────────────────
echo "Checking Python..."
if ! command -v python3 &>/dev/null; then
echo "ERROR: python3 not found. Install Python 3.10+ first."
exit 1
fi
PY_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
PY_MAJOR=$(echo "$PY_VERSION" | cut -d. -f1)
PY_MINOR=$(echo "$PY_VERSION" | cut -d. -f2)
if [ "$PY_MAJOR" -lt 3 ] || ([ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 10 ]); then
echo "ERROR: Python 3.10+ required (found $PY_VERSION)"
exit 1
fi
echo " Found Python $PY_VERSION"
# ── 2. Create venv + install deps ────────────────────────────────────────
if [ ! -d "venv" ]; then
echo ""
echo "Creating virtual environment..."
python3 -m venv venv
fi
source venv/bin/activate
echo "Installing dependencies..."
pip install -q -r requirements.txt
echo " Done."
# ── 3. Configure .env ────────────────────────────────────────────────────
echo ""
echo "========================================"
echo " Configuration"
echo "========================================"
if [ -f ".env" ]; then
echo ""
echo ".env already exists. Overwrite? (y/N)"
read -r overwrite
if [ "$overwrite" != "y" ] && [ "$overwrite" != "Y" ]; then
echo "Keeping existing .env"
SKIP_ENV=1
fi
fi
if [ "${SKIP_ENV:-}" != "1" ]; then
echo ""
echo "--- Step 1: Admin Bot Token ---"
echo "Create a bot via @BotFather on Telegram:"
echo " 1. Open Telegram, search for @BotFather"
echo " 2. Send /newbot and follow the prompts"
echo " 3. Copy the token (looks like 123456:ABC-DEF...)"
echo ""
echo "Paste your ADMIN bot token:"
read -r ADMIN_TOKEN
echo ""
echo "--- Step 2: Your Telegram User ID ---"
echo "To find your user ID:"
echo " 1. Search for @userinfobot on Telegram"
echo " 2. Send it any message"
echo " 3. It replies with your numeric user ID"
echo ""
echo "Paste your user ID:"
read -r ADMIN_ID
echo ""
echo "--- Step 3: Group Chat ID ---"
echo "To find your group chat ID:"
echo " 1. Create a Telegram group (or use an existing one)"
echo " 2. Add your admin bot to the group"
echo " 3. Send any message in the group"
echo " 4. Run this in another terminal:"
echo " curl -s https://api.telegram.org/bot${ADMIN_TOKEN}/getUpdates | python3 -m json.tool | grep '\"id\"' | head -5"
echo " 5. The negative number (like -100...) is your group ID"
echo ""
echo "Paste your group chat ID (or press Enter to skip):"
read -r GROUP_ID
GROUP_ID=${GROUP_ID:-0}
echo ""
echo "--- Step 4: LLM API Key ---"
echo "You need at least one LLM provider. Options:"
echo " 1. Kimi (moonshot.ai) — recommended, has free tier"
echo " 2. DeepSeek (platform.deepseek.com)"
echo " 3. Google Gemini (aistudio.google.com)"
echo ""
echo "Which provider? (1/2/3):"
read -r LLM_CHOICE
case "$LLM_CHOICE" in
1)
echo "Paste your Kimi API key:"
read -r LLM_KEY
LLM_LINE="KIMI_API_KEY=$LLM_KEY"
;;
2)
echo "Paste your DeepSeek API key:"
read -r LLM_KEY
LLM_LINE="DEEPSEEK_API_KEY=$LLM_KEY"
;;
3)
echo "Paste your Gemini API key:"
read -r LLM_KEY
LLM_LINE="GEMINI_API_KEY=$LLM_KEY"
;;
*)
echo "Paste your Kimi API key (default):"
read -r LLM_KEY
LLM_LINE="KIMI_API_KEY=$LLM_KEY"
;;
esac
# Write .env
cat > .env << ENVEOF
# Generated by setup.sh — $(date '+%Y-%m-%d %H:%M')
TELEGRAM_BOT_TOKEN_ADMIN=$ADMIN_TOKEN
ADMIN_USER_ID=$ADMIN_ID
GROUP_ID=$GROUP_ID
$LLM_LINE
ENVEOF
echo ""
echo ".env written."
fi
# ── 4. Create first persona ──────────────────────────────────────────────
echo ""
echo "========================================"
echo " Create Your First Persona Bot"
echo "========================================"
echo ""
echo "Each persona bot needs its own BotFather token."
echo "Give your first persona a short ID (lowercase, no spaces)."
echo "Examples: news, assistant, helper"
echo ""
echo "Persona ID (or press Enter to skip):"
read -r PERSONA_ID
if [ -n "$PERSONA_ID" ]; then
PERSONA_FILE="personas/${PERSONA_ID}.json"
if [ -f "$PERSONA_FILE" ]; then
echo " $PERSONA_FILE already exists, skipping."
else
echo "Display name for this bot (e.g. 'News Bot'):"
read -r DISPLAY_NAME
DISPLAY_NAME=${DISPLAY_NAME:-$PERSONA_ID}
echo "Paste the Telegram bot token for this persona:"
read -r PERSONA_TOKEN
# Append token to .env
UPPER_ID=$(echo "$PERSONA_ID" | tr '[:lower:]' '[:upper:]')
echo "TELEGRAM_BOT_TOKEN_${UPPER_ID}=$PERSONA_TOKEN" >> .env
# Create persona JSON
cat > "$PERSONA_FILE" << JSONEOF
{
"_comment": "Created by setup.sh",
"id": "$PERSONA_ID",
"display_name": "$DISPLAY_NAME",
"system_prompt": "You are $DISPLAY_NAME, a helpful assistant.",
"topic_names": [],
"voice_enabled": false,
"news_module": "none",
"digest_enabled": false,
"twitter_enabled": false,
"reddit_enabled": false
}
JSONEOF
echo " Created $PERSONA_FILE"
echo " Token added to .env as TELEGRAM_BOT_TOKEN_${UPPER_ID}"
fi
fi
# ── Done ──────────────────────────────────────────────────────────────────
echo ""
echo "========================================"
echo " Setup complete!"
echo "========================================"
echo ""
echo "Next steps:"
echo " 1. Edit personas/${PERSONA_ID:-example}.json to customize your bot"
echo " 2. Run: ./start_all.sh"
echo " 3. Send a message to your bot on Telegram"
echo ""
echo "Logs: tail -f /tmp/start_all.log"
echo "Stop: ./start_all.sh stop"
echo ""