Skip to content

A lightweight service that monitors Google Drive and sends real-time backup notifications to a Telex Channel πŸš€

License

Notifications You must be signed in to change notification settings

telexintegrations/telex-gdrive-notifier

Repository files navigation

πŸ“’ Telex Google Drive Notifier

πŸš€ Description

Telex Google Drive Notifier is a TypeScript Node.js application that monitors changes in a specified Google Drive folder and sends real-time notifications to the Telex App via webhooks. It detects file uploads, modifications, and deletions in real-time, ensuring that users stay updated with any changes in their Google Drive folders.

πŸ“Œ Features

βœ… Real-time monitoring of Google Drive folder changes
βœ… Instant notifications to Telex App via webhooks
βœ… TypeScript for enhanced type safety and developer experience
βœ… Google Drive API v3 integration for reliable change detection
βœ… Redis for configuration persistence and caching
βœ… Express.js server with comprehensive error handling
βœ… Jest testing framework with TypeScript support
βœ… ESLint & Prettier for code quality and formatting
βœ… Systemd service support for VPS deployment
βœ… CI/CD pipeline with GitHub Actions

πŸ›  Tech Stack

  • Runtime: Node.js v18+
  • Language: TypeScript 5.3+
  • Framework: Express.js 4.21+
  • Database: Redis 4.7+
  • API: Google Drive API v3
  • Testing: Jest 29+ with ts-jest
  • Build Tool: TypeScript Compiler (tsc)
  • Code Quality: ESLint 9+ & Prettier 3+

πŸ“¦ Installation

1️⃣ Clone the Repository

git clone https://github.com/na-cho-dev/telex-gdrive-notifier.git
cd telex-gdrive-notifier

2️⃣ Install Dependencies

npm install

3️⃣ Set Up Environment Variables

Create a .env file in the project root:

PORT=3300
GOOGLE_SERVICE_ACCOUNT_PATH=./config/service-account.json
GOOGLE_DRIVE_WEBHOOK_TOKEN='your-webhook-token-here'
TELEX_ENV='dev'
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
DEV_WEBHOOK_URL='https://your-dev-webhook-url.com'

4️⃣ Google Service Account Setup

  1. Get your Google Service Account JSON file by following this guide
  2. Save the file as service-account.json in the ./config/ directory
  3. Ensure the service account has Google Drive API access

5️⃣ Start Redis Server

# On Ubuntu/Debian
sudo systemctl start redis-server

# Or run directly
redis-server

6️⃣ Build and Start the Application

# Build TypeScript to JavaScript
npm run build

# Start the application
npm start

For development:

# Run with hot-reload using tsx
npm run dev

πŸ§ͺ Testing

Prerequisites

Ensure Redis is running:

redis-server

Run Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Generate coverage report
npm run test:coverage

πŸ”— API Endpoints

πŸ”Ή Integration JSON

GET /integration.json
Returns the Telex integration configuration

πŸ”Ή Telex Webhook

POST /tick
Registers webhook and starts monitoring Google Drive folder

Request Body:

{
  "channel_id": "your-channel-id",
  "return_url": "https://your-telex-webhook-url.com",
  "settings": [
    {
      "label": "Folder ID",
      "type": "text",
      "required": true,
      "default": "your-google-drive-folder-id"
    }
  ]
}

πŸ”Ή Google Drive Webhook

POST /gdrive-webhook
Receives notifications from Google Drive API when folder changes occur

πŸ”Ή Health Check

GET /
Returns server status and welcome message

πŸ— Build & Development

# Clean build
npm run prebuild  # Removes dist folder
npm run build     # Compiles TypeScript

# Code quality
npm run lint      # Run ESLint
npm run lint:fix  # Fix ESLint issues
npm run format    # Format code with Prettier

# Development
npm run dev       # Start with hot-reload

πŸš€ Deployment

Option 1: Manual Deployment

  1. Build the application:
npm run build
  1. Start with PM2 (recommended):
npm install -g pm2
pm2 start dist/server.js --name telex-gdrive-notifier
pm2 save
pm2 startup

Option 2: Systemd Service

  1. Create service file:
sudo nano /etc/systemd/system/telex-gdrive-notifier.service
  1. Add configuration:
[Unit]
Description=Telex GDrive Notifier
After=network.target redis.service

[Service]
Type=simple
User=root
WorkingDirectory=/root/telex-gdrive-notifier
ExecStart=/usr/bin/node dist/server.js
Restart=always
RestartSec=10
Environment=NODE_ENV=production
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
  1. Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable telex-gdrive-notifier
sudo systemctl start telex-gdrive-notifier
  1. Check status:
sudo systemctl status telex-gdrive-notifier
journalctl -u telex-gdrive-notifier -f

Option 3: Automatic Deployment with GitHub Actions

The repository includes a CI/CD pipeline that automatically deploys to DigitalOcean when you push to the main branch. Configure these secrets in your GitHub repository:

  • DO_SSH_PRIVATE_KEY: Your DigitalOcean server SSH private key
  • DO_SSH_USER: SSH username (usually root)
  • DO_SERVER_IP: Your server's IP address

πŸ“ Project Structure

telex-gdrive-notifier/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ controllers/          # Request handlers
β”‚   β”‚   β”œβ”€β”€ gdriveWebhookController.ts
β”‚   β”‚   β”œβ”€β”€ jsonIntegrationController.ts
β”‚   β”‚   └── telexWebhookController.ts
β”‚   β”œβ”€β”€ database/             # Database connections
β”‚   β”‚   β”œβ”€β”€ redisClient.ts
β”‚   β”‚   └── redisSubscriber.ts
β”‚   β”œβ”€β”€ routers/              # Route definitions
β”‚   β”‚   β”œβ”€β”€ jsonIntegrationRouter.ts
β”‚   β”‚   └── webhookRouter.ts
β”‚   β”œβ”€β”€ service/              # Business logic
β”‚   β”‚   β”œβ”€β”€ checkIfNoChanges.ts
β”‚   β”‚   β”œβ”€β”€ dataStore.ts
β”‚   β”‚   β”œβ”€β”€ googleDriveService.ts
β”‚   β”‚   β”œβ”€β”€ sendNotification.ts
β”‚   β”‚   └── startDriveWatch.ts
β”‚   β”œβ”€β”€ types/                # TypeScript type definitions
β”‚   β”‚   └── index.ts
β”‚   └── server.ts             # Application entry point
β”œβ”€β”€ __tests__/                # Test files
β”œβ”€β”€ dist/                     # Compiled JavaScript (generated)
β”œβ”€β”€ config/                   # Configuration files
β”œβ”€β”€ docs/                     # Documentation and screenshots
β”œβ”€β”€ .github/workflows/        # GitHub Actions CI/CD
β”œβ”€β”€ eslint.config.ts          # ESLint configuration
β”œβ”€β”€ jest.config.ts            # Jest testing configuration
β”œβ”€β”€ babel.config.ts           # Babel configuration
β”œβ”€β”€ tsconfig.json             # TypeScript configuration
└── package.json              # Dependencies and scripts

βš™οΈ Telex Integration Setup

  1. Add Integration URL in your Telex organization:

    https://your-domain.com/integration.json
    
  2. Configure Settings:

    • Folder ID: The Google Drive folder ID you want to monitor
    • Interval: Set to * * * * * (every minute) for real-time monitoring
  3. Get Google Drive Folder ID:

    • Open Google Drive and navigate to your target folder
    • Copy the folder ID from the URL:
    https://drive.google.com/drive/folders/1AbCdEfGhIjKlMnOpQrStUvWxYz
    
    • The folder ID is: 1AbCdEfGhIjKlMnOpQrStUvWxYz

🚦 Monitoring & Logging

Request Logging

All requests are automatically logged in the format:

[2025-02-23T12:34:56.789Z] - [GET /integration.json HTTP/1.1] - 200 OK (25ms)

Redis Monitoring

# Check Redis status
redis-cli ping

# Monitor Redis commands
redis-cli monitor

# Clear all data (if needed)
redis-cli FLUSHALL

Application Logs

# With systemd
journalctl -u telex-gdrive-notifier -f

# With PM2
pm2 logs telex-gdrive-notifier

πŸ›‘ Troubleshooting

Common Issues

  1. "Cannot read properties of undefined (reading 'Router')"

    • Ensure all dependencies are installed: npm install
    • Rebuild the project: npm run build
  2. Redis connection errors

    • Check if Redis is running: systemctl status redis-server
    • Verify Redis configuration in .env
  3. Google Drive API errors

    • Verify service account JSON file exists in ./config/
    • Ensure service account has Drive API permissions
    • Check Google Drive API quotas
  4. TypeScript compilation errors

    • Run: npx tsc --noEmit to check for type errors
    • Ensure all TypeScript dependencies are installed

πŸ“· Screenshots

Telex Integration File Change Notifications

🌐 Live Demo

The application is deployed at: https://telexgdrivenotifier.live

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“¬ Contact & Support

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

⭐ Show Your Support

If this project helped you, please consider giving it a ⭐ on GitHub!

About

A lightweight service that monitors Google Drive and sends real-time backup notifications to a Telex Channel πŸš€

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published