email-ai-agent
Gmail summaries → AI → Telegram assistant + Notion notes. Self-hosted, open source.
// Deploy, configure env vars, connect Gmail via OAuth.
// Cron runs every 30min. Summaries hit your Telegram. * prefix saves to Notion.
## Features
.gmail
Connect up to 5 Gmail accounts via OAuth2. Reads new emails automatically with read-only access — your inbox stays safe.
.summaries
Each email is summarized by OpenAI into a concise title and 2–3 bullet points. No more reading walls of text.
.telegram
Summaries are instantly sent to your Telegram chat. Social emails get a 👥 prefix, promotions get 🏷️.
.assistant
Send any message to your Telegram bot and get intelligent AI-powered replies back instantly via OpenAI.
.notion
Prefix any Telegram message with * to save as a note, or `*<name>,`, to save to a subpage in Notes with that name.
.cron
Cron-based automation checks your inboxes every 30 minutes. Deploy on Vercel or use any external cron service.
## How it works
Gmail Integration
The agent connects to up to 5 Gmail accounts via OAuth2. It reads unread messages from inbox, social, and promotions — spam is automatically skipped. Access is read-only.
You receive 12 new emails. The agent scans all connected accounts, skips spam, and processes the 8 relevant unread messages.
AI Summaries
Each email is sent to OpenAI, which returns a short title and 2–3 bullet points. You get the gist without opening the email.
A long newsletter becomes: "Q4 Product Launch Recap" — Key features shipped · Beta feedback summary · Next steps.
Telegram Delivery
Summaries are sent to your Telegram chat. Social emails get 👥 prefix, promotions get 🏷️, so you can skim by category at a glance.
You receive: "🏷️ 20% off Site-Wide — Summer sale ends Sunday · Free shipping over $50."
AI Chat Assistant
Send any message to your bot. It's forwarded to OpenAI, and the reply comes back to you in Telegram. Use it for questions, drafting, or brainstorming.
You: "Draft a 2-line reply declining the meeting." Bot: "Thank you for the invite. I won't be able to attend..."
Notion Notes
Messages that start with * (asterisk) are saved as notes in your Notion page. Use `*<name>,`, to save to a subpage in Notes with that given name.
*Call back John re: project scope by Friday → appended to main Notes. *Work, Review Q1 roadmap → saved to subpage "Work" under Notes.
Smart Scheduling
A cron job runs every 30 minutes (or on your schedule). It triggers the email check and processing. Works with Vercel Cron or any external cron service.
At 9:00, 9:30, 10:00… the agent checks for new mail, summarizes it, and sends to Telegram — no manual refresh needed.
## Config
Filtering
- -inbox, social, promotions — unread only
- -skips spam
- -skips < 5 char emails
- -👥 social · 🏷️ promotions
- -optional LABEL_FILTER
Security
- -read-only Gmail
- -password-protected utils
- -webhook secret validation
- -MAX_EMAILS_PER_RUN
- -5 accounts / 1 OAuth client
- -no DB — env vars only
## Setup & Status
Account Status
Quick Actions
## Environment Variables
Set in .env.local or deployment env. See .env.example.
GOOGLE_CLIENT_ID# OAuth client from Google Cloud Console(Email summaries)GOOGLE_CLIENT_SECRET# OAuth secret from Google Cloud Console(Email summaries)GOOGLE_REFRESH_TOKEN# One per Gmail account (use Setup Gmail)(Email summaries)OPENAI_API_KEY# API key from platform.openai.com(Summaries & Assistant)OPENAI_MODEL# Optional; default gpt-5-nano(AI)TELEGRAM_BOT_TOKEN# Create via @BotFather on Telegram(Telegram)TELEGRAM_CHAT_ID# Get from @userinfobot on Telegram(Telegram)NOTION_API_KEY# Notion integration secret(Notion notes)NOTION_NOTES_PAGE_ID# Target page ID or URL(Notion notes)APP_URL# e.g. https://yourdomain.com(Webhook & OAuth)TEST_PASSWORD# Password for utility pages(Setup pages)MAX_EMAILS_PER_RUN# Optional; default 5(Email summaries)LABEL_FILTER# Optional; e.g. IMPORTANT(Email summaries)TELEGRAM_WEBHOOK_SECRET# Optional header secret for webhook(Webhook)CRON_SECRET# Optional bearer token for cron(Scheduling)If you find this useful, star it on GitHub.
★ Star on GitHub