Logo Lanfrica

cleven12/personal-whatsapp-ai

Domain:

natural language processing

Record type:

software
Creator:
cle
Host:
πŸ“± Flask-based WhatsApp AI | Google Gemini (1.5/2.0) | Multi-key Fallback | Persistent JSON Memory | CGM Persona (Kiswahili-slang) # WhatsApp AI Bot **Personal AI assistant for WhatsApp, powered by Google Gemini** --- ## Overview A Flask-based WhatsApp chatbot that processes incoming messages via webhook and responds using Google Gemini AI. Built around a custom **CGM persona** β€” concise, playful, Kiswahili-flavored tone for personal use. --- ## Features | Feature | Description | |---|---| | **Multi-key fallback** | Rotates across multiple Gemini API keys automatically on quota exhaustion | | **Smart memory** | Stores last 4 conversation turns per user, persisted to JSON | | **Whapi integration** | Native support for Whapi.cloud webhook format | | **Auto model fallback** | Tries `gemini-2.0-flash` β†’ `gemini-2.5-flash` β†’ `gemini-1.5-flash` β†’ `gemini-1.5-pro` | | **Session expiry** | Conversations auto-expire after 24 hours of inactivity | | **Full logging** | Console + file logging (`logs/webhook.log`) | --- ## Project Structure ``` . β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ app.py # Webhook endpoints β”‚ β”œβ”€β”€ chatbot.py # Gemini integration + model fallback β”‚ β”œβ”€β”€ conversation_memory.py # JSON storage + session management β”‚ └── main.py # Entry point β”œβ”€β”€ data/conversations/ # Per-user conversation history β”œβ”€β”€ logs/webhook.log # Activity logs └── docs/ # Extended documentation ``` --- ## Quick Start ### Prerequisites - Python 3.11+ - Gemini API key β€” Get one free from Google AI Studio - *(Optional)* Whapi.cloud token for sending replies ### Setup ```bash git clone github.com cd 7ee149 pip install -r requirements.txt cp .env.example .env ``` Edit `.env`: ```env # Single key GEMINI_API_KEY=your_key_here # Multiple keys (recommended β€” each gets 1500 free requests/day) GEMINI_API_KEY=key1,key2,key3 # Optional: auto-reply via Whapi WHAPI_TOKEN=your_whapi_token WHAPI_BASE_URL=gate.whapi.cloud ``` ### Run ```bash python src/main.py ``` ### Test ```bash curl -X POST local …