CoolFace
Apppublic

luffyDTaro/Gmail_Notifications

sourceHugging Faceupdated 7mo agoView on Hugging Face
1likes
App README

๐Ÿš€ GMAIL Alert Bot

Smart Gmail โ†’ Telegram notification system for GMAIL alerts.

Monitors your Gmail for GMAIL -related emails and sends real-time notifications to your Telegram โ€” 100% FREE. Includes a premium web dashboard for live configuration.

โœจ Features

  • โ€”๏ฟฝ Web Dashboard: Configure everything from a beautiful dark-theme UI
  • โ€”๏ฟฝ๐ŸŽ› Two Alert Modes: all (every email) or filtered (smart filtering)
  • โ€”โœ… Whitelist: Only alert for specific senders or keywords
  • โ€”๐Ÿšซ Blacklist: Auto-skip spam, promos, irrelevant emails (overrides whitelist)
  • โ€”๐Ÿท Safe Processing: Uses PROCESSED_BY_BOT label โ€” no emails lost, no mark-as-read
  • โ€”๐Ÿ”„ Retry Logic: Exponential backoff if Telegram fails
  • โ€”๐Ÿ’พ Hot-Reload: Change settings from dashboard โ€” no restart needed
  • โ€”๐Ÿ“Š Live Stats: Track checks, alerts, skipped emails in real-time
  • โ€”โ˜ Free Deployment: Ready for Hugging Face Spaces

๐Ÿ“‹ Setup Guide (Step-by-Step)

Step 1: Install Dependencies

bash
cd GMAIL -alert-bot
npm install

Step 2: Create Telegram Bot & Get Chat ID

2a. Create the Bot
  1. 1.Open Telegram โ†’ search for @BotFather
  2. 2.Send /start then /newbot
  3. 3.Choose a name and username
  4. 4.Copy the Bot Token (looks like 123456:ABC-DEF...)
2b. Get Your Chat ID
  1. 1.Open Telegram โ†’ send any message (like "hi") to your new bot
  2. 2.Open this URL in browser (replace <TOKEN> with your bot token):
   https://api.telegram.org/bot<TOKEN>/getUpdates
  1. 1.Look for "chat": { "id": 123456789 } โ€” that number is your Chat ID

Step 3: Configure Environment

  1. 1.Copy the example env file:
bash
   copy .env.example .env
  1. 1.Edit .env โ€” you only need to fill in two values to get started:
env
   TELEGRAM_BOT_TOKEN=your_actual_bot_token
   TELEGRAM_CHAT_ID=your_actual_chat_id
  1. 1.Everything else (alert mode, whitelist, blacklist, etc.) can be configured later from the web dashboard.

Step 4: Set Up Gmail API (Free)

4a. Create Google Cloud Project
  1. 1.Go to Google Cloud Console
  2. 2.Click "Select a project" โ†’ "New Project"
  3. 3.Name it (e.g., "GMAIL Alert Bot") โ†’ Create
4b. Enable Gmail API
  1. 1.Go to APIs & Services โ†’ Library
  2. 2.Search for "Gmail API"
  3. 3.Click it โ†’ Enable
4c. Configure OAuth Consent Screen
  1. 1.Go to APIs & Services โ†’ OAuth consent screen
  2. 2.Select External โ†’ Create
  3. 3.Fill in:
  4. 4.App name: GMAIL Alert Bot
  5. 5.User support email: your email
  6. 6.Developer email: your email
  7. 7.Click Save and Continue through all steps
  8. 8.Go to Test users โ†’ Add Users โ†’ add your Gmail address
4d. Create OAuth Credentials
  1. 1.Go to APIs & Services โ†’ Credentials
  2. 2.Click Create Credentials โ†’ OAuth client ID
  3. 3.Application type: Desktop app
  4. 4.Name: anything (e.g., "Alert Bot")
  5. 5.Click Create
  6. 6.Click Download JSON
  7. 7.Rename the downloaded file to credentials.json
  8. 8.Place it in the project root (same folder as package.json)

Step 5: Create Gmail Filter (Optional but Recommended)

In Gmail:

  1. 1.Click the search bar โ†’ Click the filter icon โ†’ Create filter
  2. 2.Set rules like:
  3. 3.From: GMAIL OR hr
  4. 4.Subject: interview OR test OR assignment
  5. 5.Click Create filter โ†’ Check Apply label โ†’ Create label GMAIL _ALERT
  6. 6.Also check Also apply to matching conversations

Step 6: Run Setup Wizard

bash
npm run setup

This will:

  • โ€”โœ… Verify your .env configuration
  • โ€”โœ… Test Telegram bot connection
  • โ€”โœ… Guide you through Gmail OAuth (opens browser)
  • โ€”โœ… Save your auth token

Step 7: Start the Bot

bash
npm start

You'll see:

๐Ÿš€ GMAIL  Alert Bot โ€” Starting...
โœ… Gmail authenticated!
๐Ÿ“‹ PROCESSED_BY_BOT label ready
๐Ÿ“ฑ Startup notification sent to Telegram!
๐Ÿ“Š Dashboard: http://localhost:7860
๐ŸŸข Bot is running.

Open http://localhost:7860 in your browser to access the configuration dashboard!


๐ŸŒ Web Dashboard

The dashboard lets you configure everything from your browser โ€” no need to edit .env manually:

SectionWhat you can do
๐Ÿ“ฑ TelegramEdit bot token, chat ID, send test message
๐ŸŽ› Alert ModeToggle between ALL / FILTERED, set check interval & Gmail label
โœ… WhitelistAdd/remove senders & keywords with tag-based inputs
๐Ÿšซ BlacklistAdd/remove blocked senders & keywords
๐Ÿ“Š StatsView live stats โ€” checks done, alerts sent, skipped, last check time

Changes are saved to .env and applied instantly โ€” no restart needed.


๐ŸŽ› Configuration Reference

VariableDefaultDashboard?Description
TELEGRAM_BOT_TOKENโ€”โœ…Bot token from @BotFather
TELEGRAM_CHAT_IDโ€”โœ…Your Telegram chat ID
ALERT_MODEfilteredโœ…all = every email, filtered = whitelist only
CHECK_INTERVAL_MINUTES1โœ…How often to check Gmail
GMAIL_LABELGMAIL _ALERTโœ…Gmail label to watch (filtered mode)
WHITELIST_SENDERSโ€”โœ…Comma-separated sender emails
WHITELIST_KEYWORDSโ€”โœ…Comma-separated subject keywords
BLACKLIST_SENDERSโ€”โœ…Comma-separated blocked senders
BLACKLIST_KEYWORDSโ€”โœ…Comma-separated blocked keywords
PORT7860โŒServer port (set via env only)

Filtering Logic

1. Fetch unread emails (not yet processed by bot)
2. For each email:
   โ†’ If sender in BLACKLIST โ†’ SKIP
   โ†’ If subject has BLACKLIST keyword โ†’ SKIP
   โ†’ If ALERT_MODE = "all" โ†’ SEND
   โ†’ If ALERT_MODE = "filtered":
       โ†’ If sender in WHITELIST โ†’ SEND
       โ†’ If subject has WHITELIST keyword โ†’ SEND
       โ†’ Otherwise โ†’ SKIP
3. On successful Telegram send โ†’ Add PROCESSED_BY_BOT label
4. Failed sends โ†’ email stays unprocessed, retried next cycle

โ˜ Deploy on Hugging Face Spaces (Free, 24/7)

What Goes Where

Since the dashboard handles most configuration, you only need 3 things as Hugging Face Space Secrets:

SecretRequired?Why?
TELEGRAM_BOT_TOKENโœ… YesNeeded for app to start (validated on boot)
TELEGRAM_CHAT_IDโœ… YesNeeded for app to start (validated on boot)
GOOGLE_CREDENTIALSโœ… YesBase64-encoded credentials.json content
GOOGLE_TOKENโœ… YesBase64-encoded token.json content
ALERT_MODEโŒ OptionalDefaults to filtered, editable from dashboard
CHECK_INTERVAL_MINUTESโŒ OptionalDefaults to 1, editable from dashboard
GMAIL_LABELโŒ OptionalDefaults to empty, editable from dashboard
WHITELIST_*โŒ OptionalEditable from dashboard after deploy
BLACKLIST_*โŒ OptionalEditable from dashboard after deploy
โš ๏ธ Note: Dashboard changes are saved to .env in the container, but are lost on container restart. For persistent settings, set them as Hugging Face Space Secrets.

Deployment Steps

  1. 1.Create a new Space at huggingface.co/spaces
  2. 2.Select Docker as the SDK
  3. 3.Upload all project files (except .env, credentials.json, token.json)
  4. 4.Add required secrets in Space Settings โ†’ Secrets:
  5. 5.TELEGRAM_BOT_TOKEN = your bot token
  6. 6.TELEGRAM_CHAT_ID = your chat ID
  7. 7.Encode `credentials.json` and `token.json` as base64:

On your PC, run these commands to get the base64 strings:

bash
   # PowerShell
   [Convert]::ToBase64String([IO.File]::ReadAllBytes("credentials.json"))
   [Convert]::ToBase64String([IO.File]::ReadAllBytes("token.json"))

Add these as Space Secrets:

  • โ€”GOOGLE_CREDENTIALS = base64 output of credentials.json
  • โ€”GOOGLE_TOKEN = base64 output of token.json
  1. 1.Update `Dockerfile` entry point to decode secrets at startup (see below)
  2. 2.Space builds and deploys automatically โ€” your bot runs 24/7!

Updated Dockerfile (for base64 secrets)

The included Dockerfile already handles this. On startup, if GOOGLE_CREDENTIALS and GOOGLE_TOKEN environment variables exist, the app will decode them into files.


๐Ÿ“ Project Structure

GMAIL -alert-bot/
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ .env.example            # Environment template
โ”œโ”€โ”€ .env                    # Your actual config (git-ignored)
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ credentials.json        # Gmail OAuth creds (git-ignored)
โ”œโ”€โ”€ token.json              # Saved auth token (git-ignored)
โ”œโ”€โ”€ setup.js                # Interactive setup wizard
โ”œโ”€โ”€ Dockerfile              # For Hugging Face deployment
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ dashboard.html      # Web dashboard UI
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ index.js             # Main entry point + scheduler
    โ”œโ”€โ”€ config.js            # Config loader + validator
    โ”œโ”€โ”€ auth.js              # Gmail OAuth2 authentication
    โ”œโ”€โ”€ gmail.js             # Email fetching + filtering
    โ”œโ”€โ”€ telegram.js          # Telegram notifications
    โ””โ”€โ”€ dashboard.js         # Dashboard API routes

๐ŸŽฏ Resume-Worthy Description

Smart GMAIL Alert System Built a real-time email monitoring system using Node.js, Gmail API (OAuth2), and Telegram Bot API. Features a premium web dashboard for live configuration, dual alert modes with whitelist/blacklist filtering, safe-processing with custom Gmail labels, retry logic with exponential backoff, and containerized cloud deployment on Hugging Face Spaces.

๐Ÿ›  Troubleshooting

IssueSolution
credentials.json not foundDownload from Google Cloud Console (Step 4d)
No token.jsonRun npm run setup
Telegram send failedCheck BOT TOKEN and CHAT ID
Gmail auth expiredDelete token.json and run npm run setup
No notificationsCheck whitelist/filter settings on the dashboard
Dashboard not loadingMake sure bot is running (npm start)