mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-15 03:21:08 +02:00
feat(telegram-contacts-bot): add Mac Mini setup script
https://claude.ai/code/session_01LwmhvhKpEsvVtY1ZKhYu6f
This commit is contained in:
parent
3753724e82
commit
be748d2f9c
1 changed files with 144 additions and 0 deletions
144
services/telegram-contacts-bot/setup-mac-mini.sh
Executable file
144
services/telegram-contacts-bot/setup-mac-mini.sh
Executable file
|
|
@ -0,0 +1,144 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "🚀 Setting up Telegram Contacts Bot on Mac Mini..."
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
# 1. Navigate to project
|
||||
echo -e "${YELLOW}📂 Navigating to project...${NC}"
|
||||
cd ~/projects/manacore-monorepo
|
||||
|
||||
# 2. Fetch and checkout branch
|
||||
echo -e "${YELLOW}📥 Fetching latest code...${NC}"
|
||||
git fetch origin claude/research-telegram-bots-LrdWJ
|
||||
git checkout claude/research-telegram-bots-LrdWJ
|
||||
git pull origin claude/research-telegram-bots-LrdWJ
|
||||
|
||||
# 3. Navigate to bot directory
|
||||
cd services/telegram-contacts-bot
|
||||
|
||||
# 4. Create database
|
||||
echo -e "${YELLOW}🗄️ Creating database...${NC}"
|
||||
psql -U manacore -d postgres -c "CREATE DATABASE contacts_bot;" 2>/dev/null || echo "Database already exists"
|
||||
|
||||
# 5. Install dependencies
|
||||
echo -e "${YELLOW}📦 Installing dependencies...${NC}"
|
||||
pnpm install
|
||||
|
||||
# 6. Create .env file
|
||||
echo -e "${YELLOW}⚙️ Creating .env file...${NC}"
|
||||
cat > .env << 'EOF'
|
||||
# Server
|
||||
PORT=3304
|
||||
NODE_ENV=production
|
||||
TZ=Europe/Berlin
|
||||
|
||||
# Telegram
|
||||
TELEGRAM_BOT_TOKEN=8391505274:AAFaj39RulAYVZiZn9dttWxG6NCFYC6A2_8
|
||||
TELEGRAM_ALLOWED_USERS=
|
||||
|
||||
# Contacts Backend API
|
||||
CONTACTS_API_URL=http://localhost:3015
|
||||
MANA_CORE_AUTH_URL=http://localhost:3001
|
||||
|
||||
# Database
|
||||
DATABASE_URL=postgresql://manacore:devpassword@localhost:5432/contacts_bot
|
||||
|
||||
# Birthday Reminder Settings
|
||||
BIRTHDAY_CHECK_ENABLED=true
|
||||
BIRTHDAY_CHECK_TIME=08:00
|
||||
BIRTHDAY_CHECK_TIMEZONE=Europe/Berlin
|
||||
BIRTHDAY_DAYS_AHEAD=7
|
||||
EOF
|
||||
|
||||
# 7. Push database schema
|
||||
echo -e "${YELLOW}🗂️ Pushing database schema...${NC}"
|
||||
pnpm db:push
|
||||
|
||||
# 8. Build
|
||||
echo -e "${YELLOW}🔨 Building...${NC}"
|
||||
pnpm build
|
||||
|
||||
# 9. Create launchd plist for macOS
|
||||
echo -e "${YELLOW}🍎 Creating launchd service...${NC}"
|
||||
cat > ~/Library/LaunchAgents/com.manacore.telegram-contacts-bot.plist << 'EOF'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.manacore.telegram-contacts-bot</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/opt/homebrew/bin/node</string>
|
||||
<string>/Users/till/projects/manacore-monorepo/services/telegram-contacts-bot/dist/src/main.js</string>
|
||||
</array>
|
||||
<key>WorkingDirectory</key>
|
||||
<string>/Users/till/projects/manacore-monorepo/services/telegram-contacts-bot</string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>NODE_ENV</key>
|
||||
<string>production</string>
|
||||
<key>PORT</key>
|
||||
<string>3304</string>
|
||||
<key>TZ</key>
|
||||
<string>Europe/Berlin</string>
|
||||
<key>TELEGRAM_BOT_TOKEN</key>
|
||||
<string>8391505274:AAFaj39RulAYVZiZn9dttWxG6NCFYC6A2_8</string>
|
||||
<key>CONTACTS_API_URL</key>
|
||||
<string>http://localhost:3015</string>
|
||||
<key>MANA_CORE_AUTH_URL</key>
|
||||
<string>http://localhost:3001</string>
|
||||
<key>DATABASE_URL</key>
|
||||
<string>postgresql://manacore:devpassword@localhost:5432/contacts_bot</string>
|
||||
<key>BIRTHDAY_CHECK_ENABLED</key>
|
||||
<string>true</string>
|
||||
<key>BIRTHDAY_CHECK_TIME</key>
|
||||
<string>08:00</string>
|
||||
<key>BIRTHDAY_CHECK_TIMEZONE</key>
|
||||
<string>Europe/Berlin</string>
|
||||
<key>BIRTHDAY_DAYS_AHEAD</key>
|
||||
<string>7</string>
|
||||
</dict>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/Users/till/projects/manacore-monorepo/services/telegram-contacts-bot/logs/stdout.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/Users/till/projects/manacore-monorepo/services/telegram-contacts-bot/logs/stderr.log</string>
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
|
||||
# Create logs directory
|
||||
mkdir -p logs
|
||||
|
||||
# 10. Load and start service
|
||||
echo -e "${YELLOW}▶️ Starting service...${NC}"
|
||||
launchctl unload ~/Library/LaunchAgents/com.manacore.telegram-contacts-bot.plist 2>/dev/null || true
|
||||
launchctl load ~/Library/LaunchAgents/com.manacore.telegram-contacts-bot.plist
|
||||
|
||||
# Wait a moment for startup
|
||||
sleep 3
|
||||
|
||||
# 11. Check status
|
||||
echo -e "${YELLOW}🔍 Checking status...${NC}"
|
||||
if curl -s http://localhost:3304/health | grep -q "ok"; then
|
||||
echo -e "${GREEN}✅ Telegram Contacts Bot is running!${NC}"
|
||||
echo -e "${GREEN}🤖 Bot URL: https://t.me/contact_mana_bot${NC}"
|
||||
echo ""
|
||||
echo "Useful commands:"
|
||||
echo " View logs: tail -f ~/projects/manacore-monorepo/services/telegram-contacts-bot/logs/stdout.log"
|
||||
echo " Stop bot: launchctl unload ~/Library/LaunchAgents/com.manacore.telegram-contacts-bot.plist"
|
||||
echo " Start bot: launchctl load ~/Library/LaunchAgents/com.manacore.telegram-contacts-bot.plist"
|
||||
echo " Health check: curl http://localhost:3304/health"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Bot may still be starting. Check logs:${NC}"
|
||||
echo " tail -f ~/projects/manacore-monorepo/services/telegram-contacts-bot/logs/stderr.log"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue