An intelligent AI email assistant powered by Groq's LLaMA 3.3 70B and Model Context Protocol (MCP). Manage Gmail and iCloud emails via natural voice conversation on Telegram.
π£οΈ Fully Conversational AI - Bot doesn't just transcribe, it talks back!
- π Text-to-Speech (TTS) - Bot responds with voice using Groq Orpheus
- π― Smart Voice System - Only speaks conversation, not data
- π¬ Natural Q&A - Ask "What can you do?" or "Is this secure?"
- π² Dynamic Variations - Never repeats the same response twice
- π§ Off-Topic Detection - Gracefully handles non-email questions
- π Human-Like Interaction - Feels like talking to a real assistant
π€ You: "Check my Gmail"
π Bot: [Lists 10 emails in text]
π Bot: "Here are your latest 10 emails. Which one would you like me to read?"
π€ You: "Read email number 2"
π Bot: [Shows full email content]
π Bot: "Here's email number 2. Would you like me to draft a reply?"
π€ You: "Draft a reply"
π Bot: [Shows AI-generated draft]
π Bot: "I've drafted a reply for email 2. Would you like me to send it?"
π€ You: "Send it"
π Bot: "β
Reply sent!"
π Bot: "Done! Reply sent. Anything else I can help you with?"
- β Groq Whisper (STT) - Understands your voice commands
- β Groq Orpheus TTS - Responds with natural voice (diana voice)
- β Smart Voice Triggers - Only speaks when needed (conversation, not data)
- β Dynamic Variations - 3-5 response variations per action (never repeats)
- β Natural Q&A - Answers "What can you do?" and "Is this secure?"
- β Off-Topic Handling - Redirects gracefully to email tasks
- β Read Emails - Gmail (primary inbox) + iCloud
- β Send Emails - Compose via natural language
- β Advanced Search - Find by sender, subject, date, keywords
- β Draft Replies - AI-generated with approval workflow
- β Voice + Text Input - Works both ways
- β Context Awareness - Remembers conversation state
- β MCP Architecture - Modular, reusable tools
- β Dockerized - One-command deployment
Setup Commands:
/start - Initialize bot
/help - See all commands
/status - View bot memory (emails, drafts, context)
/clear - Reset session memory
Voice/Text Commands:
"Check my Gmail" - List primary inbox emails
"Check my iCloud" - List iCloud emails
"Read email number 2" - Read specific email
"Read it" - Auto-read when only 1 result
"Draft a reply" - Generate reply for last read email
"Draft a reply for email 3" - Generate reply for specific email
"Draft a reply saying I will attend" - Custom reply hint
"Send reply" - Send pending draft
"Cancel" - Cancel pending draft
"Find emails from Nike" - Search by sender
"What can you do?" - See capabilities
"Is this secure?" - Security explanation
βββββββββββββββββββ
β Telegram User β βββ Voice Input
ββββββββββ¬βββββββββ
β Voice Message
βΌ
βββββββββββββββββββββββ
β Groq Whisper API β βββ Speech-to-Text
ββββββββββ¬βββββββββββββ
β Transcribed Text
βΌ
βββββββββββββββββββββββ
β Telegram Bot β βββ Context Management
ββββββββββ¬βββββββββββββ
β Command
βΌ
βββββββββββββββββββββββ
β Groq LLaMA 3.3 70B β βββ AI Decision Making
ββββββββββ¬βββββββββββββ
β Tool Calls
βΌ
βββββββββββββββββββββββ
β MCP Client β βββ Protocol Layer
ββββββββββ¬βββββββββββββ
β JSON-RPC
βΌ
βββββββββββββββββββββββ
β MCP Server β βββ 10+ Email Tools
ββββββββββ¬βββββββββββββ
β
βΌ
βββββββββββββββββββββββ
β Email Handlers β βββ Gmail API + iCloud IMAP/SMTP
βββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββββ
β Groq Orpheus TTS β βββ Text-to-Speech (Voice Response)
βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Telegram User β βββ Voice + Text Response
βββββββββββββββββββ
ai-gmail-agent/
βββ telegram_bot/
β βββ bot.py # V4 Telegram bot (voice conversation)
βββ agent/
β βββ client.py # V2 CLI agent
β βββ mcp_client.py # MCP client wrapper
βββ mcp_server/
β βββ server.py # MCP server
β βββ email_tools.py # Gmail & iCloud handlers
βββ .env # API keys (not committed)
βββ credentials.json # Gmail OAuth (not committed)
βββ Dockerfile
βββ docker-compose.yml
βββ README.md
You'll need:
- Telegram Account - To use the bot
- Telegram Bot Token - From @BotFather
- Gmail OAuth Credentials - One-time setup (~15 min)
- Groq API Key - Free at console.groq.com
- iCloud App Password - Optional, for iCloud emails
- Open Telegram and search for @BotFather
- Send
/newbotcommand - Follow prompts:
- Bot name:
My Email Assistant - Username:
my_email_assistant_bot(must end inbot)
- Bot name:
- Copy the bot token (looks like
1234567890:ABCdef...) - Save it - you'll need it in
.env
Option A: Quick Video Tutorial
- Watch: Gmail API Setup (5 min)
Option B: Step-by-Step
- Go to Google Cloud Console
- Create new project β name it "Email Agent"
- Enable Gmail API:
- APIs & Services β Library
- Search "Gmail API" β Enable
- Create OAuth credentials:
- APIs & Services β Credentials
- Create Credentials β OAuth Client ID
- Application type: Desktop app
- Download JSON β rename to
credentials.json
- Configure OAuth consent:
- OAuth consent screen
- User type: External
- Add yourself as test user
- Scopes: Add Gmail scopes
- Go to console.groq.com
- Sign up (free - no credit card)
- API Keys β Create new key
- Copy it
Note: One Groq API key gives you access to:
- Whisper (Speech-to-Text)
- LLaMA 3.3 70B (AI reasoning)
- Orpheus TTS (Text-to-Speech)
If you want iCloud email support:
- Go to appleid.apple.com
- Sign in β Security section
- App-Specific Passwords β Generate
- Label: "Email Agent Bot"
- Copy the password (format:
xxxx-xxxx-xxxx-xxxx)
Create .env in project root:
# Telegram
TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
# Groq API (one key for everything!)
GROQ_API_KEY=gsk_your_groq_api_key_here
# iCloud (optional)
ICLOUD_EMAIL=your-email@icloud.com
ICLOUD_PASSWORD=xxxx-xxxx-xxxx-xxxxOption 1: Python (Local)
# Clone repo
git clone https://github.com/predaaaasaaaaaaa/ai-gmail-agent
cd ai-gmail-agent
# Create virtual environment
python -m venv .venv
# Activate (Windows)
.venv\Scripts\activate
# Activate (Linux/Mac)
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run Telegram bot
python telegram_bot/bot.pyFirst run: Browser will open for Gmail OAuth β sign in β allow access
Option 2: Docker (Recommended)
# Pull latest image
docker pull samymetref/ai-email-agent:v4
# Run bot
docker run -d \
--name email-bot \
-v $(pwd)/credentials.json:/app/credentials.json:ro \
-v $(pwd)/token.pickle:/app/token.pickle \
-v $(pwd)/.env:/app/.env:ro \
samymetref/ai-email-agent:v4 \
python telegram_bot/bot.py- Open Telegram
- Search for your bot (
@my_email_assistant_bot) - Send
/start - Have a voice conversation:
- π€ "Check my Gmail"
- π Bot speaks: "Here are your latest 10 emails..."
- π€ "Read email number 1"
- π Bot speaks: "Here's email number 1. Would you like me to draft a reply?"
- π€ "Yes, draft a reply"
- π Bot speaks: "I've drafted a reply. Would you like me to send it?"
Or type the same commands - works both ways!
π€ You (Voice): "Check my Gmail"
π Bot (Text):
Found 10 emails. Showing top 10:
1. From: john@company.com
Subject: Meeting tomorrow
2. From: sarah@startup.io
Subject: Project update
...
π Bot (Voice): "Here are your latest 10 emails. Which one would you like me to read?"
βββββββββββββββββββββββββββββββββββ
π€ You (Voice): "Read email number 1"
π Bot (Text):
From: john@company.com
Subject: Meeting tomorrow
Hi, can we meet tomorrow at 3pm?
Let me know!
π Bot (Voice): "Here's email number 1. Would you like me to draft a reply, or read another email?"
βββββββββββββββββββββββββββββββββββ
π€ You (Voice): "Draft a reply saying I'll be there"
π Bot (Text):
π§ DRAFT REPLY (email #1):
To: john@company.com
Subject: Re: Meeting tomorrow
Hi John,
Thank you for reaching out. I'll be there
tomorrow at 3pm. Looking forward to it!
Best regards
---
Say 'send reply' to send or 'cancel' to cancel.
π Bot (Voice): "I've drafted a reply for email number 1. Would you like me to send it?"
βββββββββββββββββββββββββββββββββββ
π€ You (Voice): "Send it"
π Bot (Text): β
Reply sent to john@company.com!
π Bot (Voice): "Done! Reply sent. Anything else I can help you with?"
π€ You: "What can you do?"
π Bot: [Full capabilities list with emojis]
π Bot: "I've listed everything I can do for you. Feel free to ask me anything!"
βββββββββββββββββββββββββββββββββββ
π€ You: "Is this secure?"
π Bot: [Complete security explanation]
π Bot: "Your data is completely safe with me. Everything stays on your device!"
π€ You: "What's the weather today?"
π Bot: "I'm an email assistant, so I focus on managing your inbox!
I can check Gmail and iCloud, read emails, draft replies, and
search messages. Try saying 'check my Gmail'!"
π Bot: "I'm focused on emails! Want me to check your inbox?"
π€ "Find emails from Nike"
π Found 2 emails:
1. From: Nike <updates@nike.com>
Subject: New collection
2. From: Nike <promo@nike.com>
Subject: 20% off sale
π "I found 2 emails. Which one would you like to read?"
π€ "Read email 1"
π "Here's email number 1. Would you like me to draft a reply?"
| Component | Technology |
|---|---|
| Bot Framework | python-telegram-bot 20.0+ |
| Speech-to-Text | Groq Whisper Large V3 |
| Text-to-Speech | Groq Orpheus (diana voice) |
| AI Reasoning | Groq LLaMA 3.3 70B |
| Protocol | Model Context Protocol (MCP) |
| Gmail | Gmail API (OAuth 2.0) |
| iCloud | IMAP/SMTP |
| Language | Python 3.11+ |
| Deployment | Docker |
# Test Telegram bot
python telegram_bot/bot.py
# Test MCP client
python test_mcp_client.py
# Test email handlers
python test_email.py# Run bot locally
python telegram_bot/bot.py
# Run with Docker
docker-compose up telegram-bot
# Rebuild Docker
docker-compose build
# View logs
docker logs -f email-botProblem: Bot shows "online" but doesn't reply
Solution:
# Check logs
python telegram_bot/bot.py
# Look for: "β
Bot ready with off-topic detection!"
# If not, check .env file has TELEGRAM_BOT_TOKENProblem: Bot says "Couldn't transcribe"
Solution:
- Check Groq API key in
.env - Verify API quota: console.groq.com
- Try shorter voice message (< 10 seconds)
Problem: Bot sends text but no voice response
Solution:
- Check Groq API daily limits (3600 tokens/day for TTS)
- Voice messages are under 200 chars each
- Wait 24 hours if rate limited
- Check logs for "β Voice sent"
Problem: "Access denied" when signing in
Solution:
- Go to Google Cloud Console
- OAuth consent screen β Add test users
- Add your Gmail address
- Delete
token.pickleand try again
Problem: "Authentication failed"
Solution:
- Use app-specific password, not regular password
- Verify
.envhas correct format:xxxx-xxxx-xxxx-xxxx - Check Apple ID security settings
Problem: Container exits immediately
Solution:
# Check files exist
ls credentials.json .env
# Check .env format
cat .env
# View container logs
docker logs email-bot
# Rebuild without cache
docker-compose build --no-cacheThe bot uses these email tools via MCP:
| Tool | Description | Example |
|---|---|---|
list_gmail_emails |
Fetch Gmail inbox | "Check my Gmail" |
list_icloud_emails |
Fetch iCloud inbox | "Check my iCloud" |
read_gmail_email |
Read Gmail content | "Read email number 1" |
read_icloud_email |
Read iCloud content | "Read email 2" |
send_gmail_email |
Send via Gmail | Used after "Send reply" |
send_icloud_email |
Send via iCloud | Auto-detected |
search_gmail |
Advanced Gmail search | "Find emails from Nike" |
search_icloud |
Search iCloud by sender | "Find iCloud from John" |
draft_gmail_reply |
Draft Gmail reply | Auto-detected |
draft_icloud_reply |
Draft iCloud reply | Auto-detected |
β
All credentials stored locally (never uploaded)
β
OAuth tokens encrypted by Google
β
API keys in .env (gitignored)
β
Draft approval required (no auto-send)
β
Voice processed via Groq (encrypted HTTPS)
β
No data stored on Telegram servers
β
Open source - audit the code yourself!
π« credentials.json - Gmail OAuth
π« token.pickle - Gmail access token
π« .env - All API keys
β
Voice transcription (Whisper) - No email content
β
AI reasoning (LLaMA) - Command interpretation only
β
Voice generation (Orpheus) - Conversational responses only
Groq NEVER sees your email content!
- Revoke access anytime: Google Account
- Delete bot anytime: Send
/deletebotto @BotFather - Use test account for development
- Keep
.envprivate - never share
Released: February 2026
New:
- π Text-to-Speech voice responses (Groq Orpheus)
- π― Smart voice system (only speaks conversation)
- π¬ Natural Q&A ("What can you do?", "Is this secure?")
- π² Dynamic response variations (never repeats)
- π§ Off-topic detection & graceful redirect
- π Human-like conversation flow
Features:
- Voice input AND output (full conversation)
- Context-aware TTS messages
- Token-optimized (200 chars max per voice)
- 3-5 response variations per action
- Capabilities & security explanations
- Friendly off-topic handling
Released: February 2026
New:
- π€ Telegram bot with voice + text support
- π§ Context-aware conversation memory
- π€ AI-powered reply generation
- π± Mobile-friendly (Telegram app)
- π Whisper transcription normalization
Released: January 2026
New:
- Model Context Protocol architecture
- 10 email tools (list, read, send, search, draft)
- Gmail advanced search
Released: January 2026
Features:
- Simple Gmail read/send
- Basic CLI commands
- π Attachment Support - Send/receive files
- ποΈ Calendar Integration - Schedule from emails
- π Push Notifications - Real-time email alerts
- π Multi-language - Support more languages
- π¨ Voice Style Selection - Choose TTS voice
- π₯ Multi-user - Family/team bot access
- π Analytics Dashboard - Email insights
MIT License - Free to use, modify, and distribute
- Groq - Fast LLaMA inference, Whisper API & Orpheus TTS
- Telegram - Bot platform
- Google - Gmail API
- Apple - iCloud IMAP/SMTP
- Anthropic - MCP protocol inspiration
- Docker Hub: samymetref/ai-email-agent
- GitHub: predaaaasaaaaaaa/ai-gmail-agent
- Groq Console: console.groq.com
- MCP Docs: modelcontextprotocol.io
Contributions welcome! Please:
- Fork the repo
- Create feature branch (
git checkout -b feature/amazing) - Commit changes (
git commit -m 'Add amazing feature') - Push branch (
git push origin feature/amazing) - Open Pull Request
Q: Is this free?
A: Yes! Groq API is free (with limits). Gmail API is free. Telegram is free.
Q: Does the bot store my emails?
A: No. Everything is processed in real-time and stored locally on your machine.
Q: Can other people use my bot?
A: No. Your bot is private. Only you can access it (unless you share the link).
Q: What if I run out of Groq credits?
A: Groq free tier: 3600 TTS tokens/day. Each voice message ~50-200 tokens. Wait 24h if you hit limits.
Q: Can I choose a different voice?
A: Yes! Edit bot.py line 363: voice="diana" β Options: diana, hannah, autumn (feminine) or troy, austin, daniel (masculine)
Q: Can I host this on a server?
A: Yes! Use Docker on any VPS (AWS, DigitalOcean, etc.). Keep .env secure.
Q: Why does the bot speak some responses but not others?
A: By design! Bot sends TEXT for data (email lists, content) and VOICE for conversation (questions, confirmations). This saves tokens and is faster.
Built with β€οΈ by Samy Metref
β Star this repo if you find it useful!
π‘ Questions? Open an issue!
π³ Docker Hub: Check latest version!
Ready to have voice conversations with your email assistant? Get started in 10 minutes! π