An end-to-end AI automation system that reads, understands, and replies to messages from:
- WhatsApp (via webhook API)
- Gmail (via Gmail API)
Powered by a locally running Qwen LLM, this system generates intelligent, human-like replies without relying on external paid APIs.
This project demonstrates how to build a real-world AI assistant that integrates with:
- WhatsApp (via Meta Cloud API + Webhooks)
- Gmail (via Gmail API + OAuth)
- Local LLM (Qwen via Hugging Face)
Unlike typical AI apps, this runs fully locally without paid APIs.
- Real-time WhatsApp auto-replies
- Automated Gmail responses
- Multi-user session memory
- Local LLM inference (Qwen 0.5B)
- Email cleaning & truncation
- Secure environment variable handling
┌──────────────┐
│ WhatsApp API │
└──────┬───────┘
│ (Webhook via ngrok)
▼
┌──────────────┐
│ FastAPI App │ ← main.py
└──────┬───────┘
▼
┌──────────────┐
│ LLM Model │ ← model.py
└──────────────┘
┌──────────────┐
│ Gmail API │
└──────┬───────┘
▼
┌──────────────┐
│ Gmail Script │ ← gmail.py
└──────┬───────┘
▼
┌──────────────┐
│ LLM Model │ ← model.py
└──────────────┘
- Clone Repo
git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git
cd YOUR_REPO
- Environment Setup
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
- Configure Environment Variables
Create .env:
EMAIL=your_email@gmail.com
OAUTH_CREDENTIALS_FILE=Oauth_cred_chatbot_gmail.json
VERIFY_TOKEN=your_verify_token
ACCESS_TOKEN=your_whatsapp_access_token
PHONE_NUMBER_ID=your_phone_number_id
- WhatsApp (Meta Cloud API)
-Create app → Add WhatsApp
Get ACCESS_TOKEN, PHONE_NUMBER_ID-Set webhook:https://your-ngrok-url/webhook
- ngrok
ngrok http 8000
- Gmail API Enable Gmail API in Google Cloud Setup OAuth Consent Screen Download credentials JSON
-
Create a .env file:
EMAIL=your_email@gmail.com OAUTH_CREDENTIALS_FILE=Oauth_cred_chatbot_gmail.json VERIFY_TOKEN=your_verify_token ACCESS_TOKEN=your_whatsapp_access_token PHONE_NUMBER_ID=your_phone_number_id
-- Running the App
uvicorn main:app --reload
ngrok http 8000
python gmail.py
- FastAPI webhook server
- Handles WhatsApp events
- Routes messages to LLM
- Fetches unread emails
- Cleans + truncates content
- Sends AI-generated replies
- Loads Qwen LLM
- Maintains session memory
- Generates responses using chat templates
| File | Responsibility |
|---|---|
| main.py | WhatsApp webhook handler |
| gmail.py | Email processing & replies |
| model.py | LLM + session memory |
- First run loads model into memory (~5–10 sec)
- CPU inference: ~2–4 sec per response
- Input size significantly affects latency
- FastAPI
- Qwen 0.5B
- Flask
- Gmail API
- WhatsApp API
- ngrok