Skip to content

Latest commit

 

History

History
125 lines (101 loc) · 3.19 KB

File metadata and controls

125 lines (101 loc) · 3.19 KB

Telegram Monitor Backend - Deployment Guide

Deploy to loamy VM (GCP)

1. Upload backend code to loamy

# From your local machine
cd ~/telegram-monitor
tar -czf backend.tar.gz backend/
gcloud compute scp backend.tar.gz loamy:~ --zone=us-central1-a

2. SSH into loamy and extract

gcloud compute ssh loamy --zone=us-central1-a

# On loamy VM
mkdir -p ~/telegram-monitor
cd ~/telegram-monitor
tar -xzf ~/backend.tar.gz
cd backend

3. Build and run with Docker

# Build the image
sudo docker build -t telegram-monitor .

# Run the container
sudo docker run -d \
  --name telegram-monitor \
  --restart unless-stopped \
  -p 5000:5000 \
  -e POSTGRES_HOST=n8n-postgres-1 \
  -e POSTGRES_PORT=5432 \
  -e POSTGRES_DB=n8n \
  -e POSTGRES_USER=n8n_postgres_admin \
  -e POSTGRES_PASSWORD=n8n_secure_admin_9c84428c14b23127cc30411c8ac173f9 \
  -e DEFAULT_API_ID=36615002 \
  -e DEFAULT_API_HASH=ca45fcd37e884102c988771b606e2e09 \
  --network n8n_default \
  -v ~/telegram-monitor/sessions:/app/sessions \
  telegram-monitor

4. Verify it's running

# Check container status
sudo docker ps | grep telegram-monitor

# Check logs
sudo docker logs telegram-monitor

# Test the API
curl http://localhost:5000/api/health

5. Set up external access with Cloudflare Tunnel

# Install cloudflared (if not already installed)
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb

# Run tunnel
cloudflared tunnel --url http://localhost:5000

Database Schema

The backend will automatically create these tables on first run:

  • accounts - Telegram accounts
  • monitors - Channel monitoring configurations
  • telegram_messages - Complete message data with media

Environment Variables

  • POSTGRES_HOST - PostgreSQL host (use container name for Docker network)
  • POSTGRES_PORT - PostgreSQL port (default: 5432)
  • POSTGRES_DB - Database name
  • POSTGRES_USER - Database user
  • POSTGRES_PASSWORD - Database password
  • DEFAULT_API_ID - Telegram API ID
  • DEFAULT_API_HASH - Telegram API Hash

API Endpoints

  • GET /api/health - Health check
  • POST /api/auth/request-code - Request Telegram auth code
  • POST /api/auth/verify-code - Verify auth code
  • GET /api/accounts - List accounts
  • GET /api/accounts/:id/channels - List channels for account
  • GET /api/monitors - List monitors
  • POST /api/monitors - Create monitor
  • PUT /api/monitors/:id - Update monitor
  • DELETE /api/monitors/:id - Delete monitor
  • GET /api/monitors/:id/poll - Poll messages (for n8n)

Troubleshooting

Container won't start

# Check logs
sudo docker logs telegram-monitor

# Check if PostgreSQL is accessible
sudo docker exec -it telegram-monitor ping n8n-postgres-1

Database connection issues

# Verify network
sudo docker inspect telegram-monitor | grep -A 10 NetworkSettings

# Test PostgreSQL connection
sudo docker exec -it n8n-postgres-1 psql -U n8n_postgres_admin -d n8n -c '\l'

Session files not persisting

# Check volume mount
sudo docker inspect telegram-monitor | grep -A 5 Mounts

# Verify sessions directory
ls -la ~/telegram-monitor/sessions/