Spectra is a hackathon-grade backend that connects:
- FastAPI (main API + webhook)
- WhatsApp Bridge (Go / whatsmeow on
:8080) for sending/receiving messages - Gemini 2.5 Flash for responses
- MCP servers (NASA + GIS) for satellite/weather + NDVI calculation
- gTTS for MP3 voice notes (no ffmpeg / pydub)
This repo is designed to be demo-ready quickly: QR login, WhatsApp webhook, morning brief scheduler, and static MP3 hosting.
Farmer WhatsApp
↕ (whatsmeow)
WhatsApp Bridge (Go) :8080
↕ (HTTP POST)
FastAPI Backend :8000
↕
Gemini 2.5 Flash + MCP (NASA/GIS)
↕
gTTS → MP3 saved to backend/static/audio
- WhatsApp QR login in terminal (scannable QR)
- Inbound WhatsApp webhook → AI reply
- Tool-calling via MCP:
- NASA MCP: satellite/weather context
- GIS MCP: NDVI computation
- Voice notes:
- MP3 only using
gTTS - Served via
/static(for downloading if needed) - No extra localhost link message after sending audio
- MP3 only using
- Scheduler:
- Runs “morning brief” once immediately on startup (demo)
- Then sleeps (default 24h)
| Service | Path | Port |
|---|---|---|
| FastAPI backend | d:\Spectra\backend |
8000 |
| WhatsApp bridge | d:\Spectra\whatsapp-mcp\whatsapp-bridge |
8080 |
- Python 3.10+ recommended
- MongoDB URI (local or Atlas)
Install dependencies:
cd d:\Spectra\backend
pip install -r requirements.txt- Go 1.21+ recommended
cd d:\Spectra\whatsapp-mcp\whatsapp-bridge
go mod tidy
go run .Create d:\Spectra\.env (repo root). Example:
# Gemini
GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY
GEMINI_MODEL=gemini-2.5-flash
# MongoDB
MONGO_URI=mongodb://localhost:27017
# Optional: SMTP (OTP email)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=you@gmail.com
SMTP_PASS=app_password
# Optional: bridge -> backend webhook override
BACKEND_WEBHOOK_URL=http://localhost:8000/whatsapp-webhookNote: If Gemini returns
403 ... API key was reported as leaked, you must generate a new key.
cd d:\Spectra\whatsapp-mcp\whatsapp-bridge
go run .Scan the QR in WhatsApp: WhatsApp → Linked Devices → Link a Device
Bridge REST endpoints:
POST http://localhost:8080/api/sendPOST http://localhost:8080/api/send_audio
cd d:\Spectra\backend
uvicorn main:app --reload --port 8000Backend routes:
GET /→ healthPOST /whatsapp-webhook→ WhatsApp inbound messagesPOST /send-otp/POST /verify-otpPOST /save(supports both farmer registration + insurance save)POST /admin/run-morning-briefGET /api/farmersGET /api/claims
Static MP3:
GET /static/...
- User sends a WhatsApp message to the connected WhatsApp account.
- The bridge forwards it to FastAPI
/whatsapp-webhook. - The backend:
- loads user profile (Mongo)
- calls Gemini 2.5 Flash
- optionally calls tools (MCP NASA/GIS)
- The backend replies via bridge
/api/send. - If voice is enabled, backend generates MP3 via
gTTSand sends audio via/api/send_audio.
If the user message contains “health”, “crop health”, or “ndvi”, the agent is expected to:
- fetch satellite/weather context using NASA MCP
- compute NDVI using GIS MCP
- send a simplified “crop greenness/health” explanation (no heavy jargon)
CORS is configured to allow any localhost / 127.0.0.1 port.
If your frontend runs on a different host/IP, add it to CORS settings in backend/main.py.
This is a CORS preflight failure. Confirm your browser’s Origin header is localhost or 127.0.0.1. If not, update CORS in backend/main.py.
The bridge must convert phone numbers to number@s.whatsapp.net. Ensure your bridge build includes the JID normalization fix.
WhatsApp may block proactive sends to numbers that never messaged you. For demo reliability:
- have the judge send “hi” first
- then reply / send brief
The agent uses a hardened JSON extraction + fallback-to-text to avoid crashes. If it still happens, log the raw model output and tighten the prompt.
backend/main.py— FastAPI app + routes + CORS + staticagent.py— WhatsApp message handling + Gemini logicbrain.py— tools definitions + system promptscheduler.py— morning brief job + loopvoice_service.py— gTTS MP3 generation + send audiodatabase.py— MongoDB users/claimsstatic/audio/— generated MP3 files
whatsapp-mcp/whatsapp-bridge/main.go— whatsmeow client + REST API + QR login
- Start bridge (
:8080) - Start backend (
:8000) - Send WhatsApp message from phone: “health of my crops”
- Show: MCP tools → AI response → voice note reply
Hackathon/demo use