Skip to content

A powerful, configurable automation hub for monitoring emails and handling webhooks with Telegram notifications

Notifications You must be signed in to change notification settings

devidence-dev/automation-hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Automation Hub

Go Version Docker Platform License

CI/CD Pipeline Security CodeQL Dependency Check Go Report Card codecov

A powerful, configurable automation hub for monitoring emails and handling webhooks with Telegram notifications

๐Ÿ›ก๏ธ Security & Quality

This project implements comprehensive security and code quality measures:

  • ๐Ÿ” Static Code Analysis - golangci-lint, gosec, CodeQL
  • ๐Ÿ•ต๏ธ Secret Detection - TruffleHog, GitLeaks, Semgrep
  • ๐Ÿ”’ Vulnerability Scanning - govulncheck, Nancy, Trivy
  • ๐Ÿค– Automated Dependency Updates - Dependabot
  • ๐Ÿ“Š Code Coverage - Codecov integration
  • ๐Ÿš€ CI/CD Pipeline - Automated testing and security checks

โœจ Features

  • ๐Ÿ“ง Real-time email monitoring - IMAP-based email processing with configurable polling
  • ๐Ÿ”ง Dynamic service configuration - Add new email processors without code changes
  • ๐Ÿค– Telegram notifications - Organized notifications with custom formatting per service
  • ๐Ÿ”— Configurable webhook support - Handles qBittorrent and other webhook integrations with custom messages
  • ๐Ÿ—๏ธ Modular architecture - Clean, extensible, and maintainable codebase
  • ๐Ÿš€ Docker ready - Optimized for Raspberry Pi 5 and cloud deployment

๐ŸŽฏ Quick Start

๐Ÿ“‹ Prerequisites

Component Version Notes
Go 1.24.5+ For local development
Docker 20.10+ Required for deployment
Docker Compose 2.0+ Orchestration

Supported Platforms: ARM64 (Raspberry Pi 5), AMD64


โš™๏ธ Configuration

๐Ÿ” Step 1: Setup Configuration

# Copy example configuration
cp configs/config.yaml.example configs/config.yaml

๐Ÿ“ Step 2: Configure Services

The new dynamic service system allows you to add email processors through configuration only:

server:
  address: ":8080"

email:
  host: "imap.gmail.com"
  port: 993
  username: "your-email@gmail.com"
  password: "your-app-password"
  polling_interval: 30  # Seconds between email checks
  
  # ๐Ÿš€ Dynamic service configuration - Add any email processor here!
  services:
    - name: "cloudflare"
      config:
        email_from: "noreply@notify.cloudflare.com"
        email_subject:
          - "your-domain.com"
        telegram_chat_id: "YOUR_CLOUDFLARE_CHAT_ID"
        telegram_message: "๐Ÿ›ก๏ธ Cloudflare Code: ```%s```"
        # code_pattern: "\\b\\d{6}\\b"  # Optional: custom regex
        
    - name: "perplexity"
      config:
        email_from: "team@mail.perplexity.ai"
        email_subject:
          - "Sign in to Perplexity"
        telegram_chat_id: "YOUR_PERPLEXITY_CHAT_ID"
        telegram_message: "๐Ÿ”ฎ Perplexity Code: ```%s```"
        
    # โž• Add more services here without touching code!

# ๐Ÿ”— Webhook Configuration
hook:
  - name: "qbittorrent"
    config:
      telegram_chat_id: "YOUR_QBITTORRENT_CHAT_ID"
  telegram_message: "๐Ÿ“ฅ **Download completed successfully!** ๐ŸŽฌ \n๐Ÿ” **Name:**  \n%s\n๐Ÿ“ **Path:**  \n%s"
  # Add more webhooks here:
  # - name: "sonarr"
  #   config:
  #     telegram_chat_id: "YOUR_SONARR_CHAT_ID"
  #     telegram_message: "๐Ÿ“บ Serie descargada: %s"

telegram:
  bot_token: "YOUR_BOT_TOKEN"
  chat_ids:
    torrent: "YOUR_TORRENT_CHAT_ID"

๐Ÿค– Step 3: Setup Telegram Bot

  1. Create a bot: Message @BotFather โ†’ /newbot
  2. Get bot token: Save the token from BotFather
  3. Get chat IDs:
    • Add your bot to the desired chats
    • Send a message, then visit: https://api.telegram.org/bot<TOKEN>/getUpdates
    • Find the chat.id values

๐Ÿณ Deployment

๐Ÿš€ Option 1: Docker Compose (Recommended)

# Clone repository
git clone <your-repo-url>
cd automation-hub

# Configure
cp configs/config.yaml.example configs/config.yaml
# Edit configs/config.yaml with your credentials

# Deploy
docker-compose up -d

# View logs
docker-compose logs -f automation-hub

๐Ÿ”ง Option 2: Manual Docker

# Build for your platform
docker build -f deployments/docker/Dockerfile -t automation-hub .

# Run with volume mount
docker run -d \
  --name automation-hub \
  --restart unless-stopped \
  -v $(pwd)/configs/config.yaml:/root/configs/config.yaml:ro \
  automation-hub

๏ฟฝ Option 3: Local Development

# Install dependencies
go mod download

# Run application
go run cmd/automation-hub/main.go

# Run tests
go test ./...

๏ฟฝ API & Webhooks

๐Ÿ“ก Available Endpoints

Endpoint Method Description
/webhook/qbitorrent POST qBittorrent completion notifications

๐Ÿ“ฆ qBittorrent Integration

Configure qBittorrent to send webhooks on completion. The webhook now supports custom messages configured in your config.yaml:

Tools โ†’ Options โ†’ Downloads โ†’ Run external program on torrent completion:

curl -X POST http://your-server:8080/webhook/qbitorrent \
  -H "Content-Type: application/json" \
  -d '{"torrent_name":"%N","save_path":"%F"}'

๐Ÿ“ Custom Message Configuration:

You can customize the notification message in your config.yaml:

hook:
  - name: "qbittorrent"
    config:
      telegram_chat_id: "YOUR_CHAT_ID"
  telegram_message: "๐ŸŽฌ Your custom message! \n๐Ÿ“ File: %s\n๐Ÿ“‚ Location: %s"

The %s placeholders will be replaced with:

  1. First %s โ†’ Torrent name
  2. Second %s โ†’ Save path

๐Ÿ†• Adding New Webhooks

The system now supports configurable webhooks! Add new webhook handlers without coding:

hook:
  - name: "qbittorrent"
    config:
      telegram_chat_id: "TORRENT_CHAT_ID"
  telegram_message: "๐Ÿ“ฅ Download complete: %s in %s"
  - name: "sonarr"
    config:
      telegram_chat_id: "SONARR_CHAT_ID" 
  telegram_message: "๐Ÿ“บ New series: %s"
  - name: "radarr"
    config:
      telegram_chat_id: "RADARR_CHAT_ID"
  telegram_message: "๐ŸŽฌ New movie: %s"

Each webhook can have:

  • โœ… Custom chat destination
  • โœ… Personalized message format
  • โœ… Multiple parameter placeholders

๐Ÿ”„ Adding New Email Services

The magic โœจ of this system is that you can add new email processors without writing any code:

# Just add to your config.yaml:
email:
  services:
    - name: "github"
      config:
        email_from: "noreply@github.com"
        email_subject: ["verification code"]
        telegram_chat_id: "YOUR_CHAT_ID"
        telegram_message: "๐Ÿ™ GitHub Code: ```%s```"
        code_pattern: "\\b\\d{6}\\b"  # Custom regex for 6-digit codes

That's it! The system will automatically:

  • โœ… Monitor emails from the specified sender
  • โœ… Match subject patterns
  • โœ… Extract codes using the pattern
  • โœ… Send formatted Telegram notifications

๐Ÿ”ง External Service Setup

๐Ÿ“ง Gmail Configuration

  1. Enable 2FA: Go to Google Account Security
  2. Generate App Password:
    • Security โ†’ 2-Step Verification โ†’ App passwords
    • Select "Mail" and generate password
  3. Use App Password: Use the generated password in config.yaml

๐Ÿดโ€โ˜ ๏ธ qBittorrent Setup

  1. Tools โ†’ Options โ†’ Downloads
  2. Run external program on torrent completion:
    curl -X POST http://localhost:8080/webhook/qbitorrent \
      -H "Content-Type: application/json" \
      -d '{"torrent_name":"%N","save_path":"%F"}'

๐Ÿ“ Message Customization:

  • Edit telegram_message in your config.yaml
  • Use %s placeholders for torrent name and save path
  • Supports Markdown formatting for rich notifications
  • All example messages have been translated to English; customize freely.

๏ฟฝ Monitoring & Logs

๐Ÿ” Viewing Logs

# Docker Compose
docker-compose logs -f automation-hub

# Docker
docker logs -f automation-hub

# Local development
# Logs output to stdout with structured JSON format

๐Ÿ“ Log Locations

  • Docker: Logs rotate automatically with size and time limits
  • Local: Standard output with structured logging
  • Production: JSON format for easy parsing and monitoring

๐Ÿ› ๏ธ Troubleshooting

๐Ÿšจ Common Issues

๐Ÿ“ง IMAP Connection Failed
# Check your config.yaml:
email:
  host: "imap.gmail.com"  # Correct IMAP server
  port: 993               # Correct port (usually 993 for SSL)
  username: "your-email@gmail.com"
  password: "app-password"  # Use app password, not regular password!

Solutions:

  • โœ… Use app password for Gmail (not your regular password)
  • โœ… Enable 2FA and generate app password
  • โœ… Check firewall settings
  • โœ… Verify IMAP is enabled in email provider
๐Ÿค– Telegram Notifications Not Working

Check the basics:

  • โœ… Bot token is correct
  • โœ… Chat IDs are correct (including negative sign for groups)
  • โœ… Bot has permission to send messages
  • โœ… Bot is added to the target chat/group

Get chat ID:

# Send a message to your bot, then:
curl https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
๐Ÿ”— Webhooks Not Received

Debugging steps:

  • โœ… Check if port 8080 is accessible
  • โœ… Verify JSON payload format matches expected: {"torrent_name":"...", "save_path":"..."}
  • โœ… Verify webhook configuration exists in config.yaml
  • โœ… Check application logs for errors
  • โœ… Test with curl manually:
    curl -X POST http://localhost:8080/webhook/qbitorrent \
      -H "Content-Type: application/json" \
      -d '{"torrent_name":"Test Movie","save_path":"/downloads/movies/"}'
๐ŸŽจ Webhook Message Not Formatting

Check your config:

hook:
  - name: "qbittorrent"
    config:
      telegram_chat_id: "123456789"  # Correct chat ID
      telegram_message: "Download: %s in %s"  # Two %s placeholders

Common issues:

  • โœ… Ensure you have exactly 2 %s placeholders for qBittorrent
  • โœ… Check that the webhook name matches exactly ("qbittorrent")
  • โœ… Verify chat ID is correct (including negative sign for groups)

Authors and acknowledgment ๐Ÿ›ก

PX1 - devidence.dev ยฉ

๐Ÿ“„ License

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


Made with โค๏ธ for automation enthusiasts

Stars Forks

About

A powerful, configurable automation hub for monitoring emails and handling webhooks with Telegram notifications

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •