-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·196 lines (165 loc) · 5.55 KB
/
setup.sh
File metadata and controls
executable file
·196 lines (165 loc) · 5.55 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
#!/bin/bash
# Telegram Bot Setup Script
# Connect MARVIN to Telegram for mobile AI assistant access
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Get the directory where this script lives
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MARVIN_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Telegram Bot Setup for MARVIN${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Check Python
if command -v python3 &> /dev/null; then
PYTHON_VERSION=$(python3 --version 2>&1 | cut -d' ' -f2)
echo -e "${GREEN}✓ Python installed (${PYTHON_VERSION})${NC}"
else
echo -e "${RED}✗ Python 3 not found${NC}"
echo " Install Python 3.10+ from https://python.org"
exit 1
fi
# Check pip
if command -v pip3 &> /dev/null; then
echo -e "${GREEN}✓ pip installed${NC}"
else
echo -e "${RED}✗ pip not found${NC}"
echo " Install pip: python3 -m ensurepip"
exit 1
fi
# Check for Anthropic API key
if [ -n "$ANTHROPIC_API_KEY" ]; then
echo -e "${GREEN}✓ ANTHROPIC_API_KEY found in environment${NC}"
else
# Check .env file
if [ -f "$MARVIN_ROOT/.env" ] && grep -q "ANTHROPIC_API_KEY" "$MARVIN_ROOT/.env"; then
echo -e "${GREEN}✓ ANTHROPIC_API_KEY found in .env${NC}"
else
echo -e "${YELLOW}! ANTHROPIC_API_KEY not found${NC}"
echo " You'll need to set this before running the bot."
echo " Get your key at: https://console.anthropic.com/settings/keys"
fi
fi
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Step 1: Create Telegram Bot${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
echo "You need a Telegram bot token from @BotFather."
echo ""
echo "1. Open Telegram and search for @BotFather"
echo "2. Send: /newbot"
echo "3. Choose a name (e.g., 'My MARVIN')"
echo "4. Choose a username (must end in 'bot', e.g., 'my_marvin_bot')"
echo "5. BotFather will give you a token like:"
echo " 123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
echo ""
echo -e "${YELLOW}Paste your bot token:${NC}"
read -rs BOT_TOKEN
echo ""
# Validate token format (basic check)
if [[ ! "$BOT_TOKEN" =~ ^[0-9]+:[A-Za-z0-9_-]+$ ]]; then
echo -e "${RED}✗ Token format doesn't look right${NC}"
echo " Should be like: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
exit 1
fi
echo -e "${GREEN}✓ Token format looks valid${NC}"
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Step 2: User Authorization (Optional)${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
echo "For security, you can restrict the bot to specific Telegram users."
echo "If you skip this, anyone who finds your bot can use it."
echo ""
echo "To get your user ID:"
echo " 1. Message @userinfobot on Telegram"
echo " 2. It will reply with your user ID"
echo ""
echo -e "${YELLOW}Enter your Telegram user ID (or press Enter to skip):${NC}"
read -r USER_ID
if [ -n "$USER_ID" ]; then
if [[ "$USER_ID" =~ ^[0-9]+$ ]]; then
echo -e "${GREEN}✓ User ID set: ${USER_ID}${NC}"
ALLOWED_USERS="$USER_ID"
else
echo -e "${YELLOW}! That doesn't look like a user ID, skipping${NC}"
ALLOWED_USERS=""
fi
else
echo -e "${YELLOW}! Skipped - bot will accept messages from anyone${NC}"
ALLOWED_USERS=""
fi
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Step 3: Install Dependencies${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Create virtual environment
if [ ! -d "$SCRIPT_DIR/venv" ]; then
echo "Creating virtual environment..."
python3 -m venv "$SCRIPT_DIR/venv"
fi
echo "Activating virtual environment..."
source "$SCRIPT_DIR/venv/bin/activate"
echo "Installing dependencies..."
pip install -q --upgrade pip
pip install -q -r "$SCRIPT_DIR/requirements.txt"
echo -e "${GREEN}✓ Dependencies installed${NC}"
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Step 4: Save Configuration${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Create or update .env file
ENV_FILE="$SCRIPT_DIR/.env"
# Write config
cat > "$ENV_FILE" << EOF
# Telegram Bot Configuration
# Generated by setup.sh
TELEGRAM_BOT_TOKEN=$BOT_TOKEN
EOF
if [ -n "$ALLOWED_USERS" ]; then
echo "TELEGRAM_ALLOWED_USERS=$ALLOWED_USERS" >> "$ENV_FILE"
fi
echo -e "${GREEN}✓ Configuration saved to .env${NC}"
# Create run script
cat > "$SCRIPT_DIR/run.sh" << 'EOF'
#!/bin/bash
# Start the MARVIN Telegram bot
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Activate virtual environment
source "$SCRIPT_DIR/venv/bin/activate"
# Load environment variables
if [ -f "$SCRIPT_DIR/.env" ]; then
export $(grep -v '^#' "$SCRIPT_DIR/.env" | xargs)
fi
# Run the bot
cd "$SCRIPT_DIR"
python telegram_bot.py "$@"
EOF
chmod +x "$SCRIPT_DIR/run.sh"
echo -e "${GREEN}✓ Run script created${NC}"
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${GREEN} Setup Complete!${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
echo "To start your bot:"
echo ""
echo -e " ${YELLOW}./.marvin/integrations/telegram/run.sh${NC}"
echo ""
echo "Then open Telegram and message your bot!"
echo ""
echo "Try these commands:"
echo -e " ${YELLOW}/start${NC} - See what the bot can do"
echo -e " ${YELLOW}/help${NC} - List available commands"
echo ""
echo -e "${GREEN}You're all set!${NC}"
echo ""