WhatsApp bot that helps users sell books on Mercado Livre. Send a photo of your book, and the agent handles everything: identifies the book, suggests a price, and creates the listing automatically.
- WhatsApp Integration: Receive messages, images, and audio via WAHA (WhatsApp HTTP API)
- Image Analysis: Uses GPT-4 Vision to identify books from cover photos
- Price Research: Scrapes Mercado Livre to suggest competitive prices based on market data
- Automatic Listings: Creates listings with proper attributes, categories, and uploaded images
- OAuth Authentication: Secure Mercado Livre authorization flow
- Conversation Memory: Persists chat history in PostgreSQL
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ WhatsApp │────▶│ WAHA │────▶│ FastAPI │
│ User │◀────│ (Docker) │◀────│ Webhook │
└─────────────────┘ └─────────────────┘ └────────┬────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐
│ PostgreSQL │◀────│ LangGraph │
│ (Persistence) │ │ Agent │
└─────────────────┘ └────────┬────────┘
│
┌────────────────────┼────────────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ GPT-4o │ │ Mercado Livre│ │ Price │
│ Vision │ │ API │ │ Scraper │
└──────────────┘ └──────────────┘ └──────────────┘
- Python 3.11+
- LangGraph - Agent state machine and tool orchestration
- LangChain - LLM integration (OpenAI GPT-4o)
- FastAPI - Webhook server for WhatsApp messages
- WAHA - WhatsApp HTTP API (Docker)
- PostgreSQL - Conversation persistence
- httpx - Async HTTP client for API calls
src/
├── auth/
│ ├── mercadolivre.py # OAuth flow and token management
│ └── routes.py # Auth endpoints
├── database/
│ ├── models.py # SQLAlchemy models
│ └── repository.py # Data access layer
├── runners/
│ ├── whatsapp/
│ │ ├── client.py # WAHA API client
│ │ ├── handlers.py # Message processing
│ │ └── runner.py # WhatsApp API runner
│ ├── stream.py # Terminal streaming mode
│ └── sync.py # Terminal sync mode
├── tools/
│ ├── mercadolivre.py # ML listing tools
│ └── mcp.py # MCP tools loader
├── graph.py # LangGraph workflow
├── nodes.py # Agent nodes
├── prompts.py # System prompts
├── state.py # Agent state definition
└── media.py # Audio transcription & image processing
git clone https://github.com/yourusername/vendeai.git
cd vendeai
python -m venv .venv
source .venv/bin/activate
pip install -e .cp .env.example .envEdit .env with your credentials:
# OpenAI
OPENAI_API_KEY=sk-...
# Mercado Livre OAuth
ML_CLIENT_ID=your-app-id
ML_CLIENT_SECRET=your-app-secret
ML_REDIRECT_URI=http://localhost:8000/auth/ml/callback
# Server
BASE_URL=http://localhost:8000
PORT=8000
# PostgreSQL
POSTGRES_URL=host=localhost port=5432 dbname=agent user=postgres password=postgres
# WAHA
WAHA_URL=http://localhost:3000
WAHA_SESSION=default
WAHA_API_KEY=your-secret-keydocker compose up -dThis starts:
- PostgreSQL on port 5432
- WAHA on port 3000
# WhatsApp API mode (production)
python main.py --api
# Terminal mode (testing)
python main.py --stream- Open http://localhost:3000 (WAHA dashboard)
- Scan the QR code with WhatsApp
- Start chatting!
- User sends a message on WhatsApp
- Bot checks if user is connected to Mercado Livre
- If not, sends OAuth authorization link
- User sends a photo of the book
- GPT-4 Vision identifies title, author, and details
- Bot suggests a price based on market research
- User confirms details
- Bot creates the listing on Mercado Livre
- User receives the listing link
| Tool | Description |
|---|---|
check_connection |
Verifies if user is authenticated with ML |
get_price_suggestion |
Scrapes ML to find market prices for similar items |
search_category |
Finds the appropriate ML category for a product |
create_listing |
Creates a listing with images, attributes, and description |
python main.py # Sync terminal mode
python main.py --stream # Streaming terminal mode
python main.py --whatsapp # WhatsApp terminal simulation
python main.py --api # WhatsApp API server (production)
python main.py --api -p 3001 # Custom portMIT