metadata
title: PropBot
emoji: π€
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
short_description: WhatsApp AI Bot with Supabase integration
PropBot - WhatsApp AI Bot
A WhatsApp chatbot powered by OpenAI GPT-4 and integrated with Supabase for user management.
Features
- π€ AI-powered chat responses using OpenAI GPT-4
- π± WhatsApp Business API integration
- π₯ User management with Supabase database
- π Conversation memory and context
- π User activity tracking
- π RESTful API endpoints for user management
Setup
1. Environment Variables
Create a .env file with the following variables:
# WhatsApp Business API
VERIFY_TOKEN=your_webhook_verify_token
PHONE_NUMBER_ID=your_phone_number_id
WHATSAPP_API_TOKEN=your_whatsapp_api_token
# OpenAI
OPENAI_API_KEY=your_openai_api_key
# Supabase
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_anon_key
2. Supabase Setup
- Create a new Supabase project at supabase.com
- Go to the SQL Editor in your Supabase dashboard
- Run the SQL script from
supabase_setup.sqlto create the users table - Copy your project URL and anon key from Settings > API
3. WhatsApp Business API Setup
- Create a Meta Developer account
- Set up a WhatsApp Business app
- Configure webhook URL:
https://your-domain.com/webhook - Set the verify token in your environment variables
4. Installation
pip install -r requirements.txt
5. Running the Application
uvicorn main:app --host 0.0.0.0 --port 8000
API Endpoints
Webhook Endpoints
GET /webhook- WhatsApp webhook verificationPOST /webhook- Receive WhatsApp messages
User Management
GET /users/{wa_id}- Get user by WhatsApp IDGET /users- List all users (with pagination)PUT /users/{wa_id}- Update user name
Health & Testing
GET /ping- Simple health checkGET /health- Detailed service statusPOST /chat- Direct AI chat endpoint
Database Schema
Users Table
users
-----
- wa_id (TEXT, PRIMARY KEY) - WhatsApp user ID
- name (TEXT) - User's display name
- created_at (TIMESTAMP) - Account creation time
- updated_at (TIMESTAMP) - Last activity time
Features
User Management
- Automatic user creation when first message is received
- User name updates from WhatsApp profile
- Activity tracking with automatic timestamp updates
AI Chat
- Context-aware conversations using user names
- Conversation memory (last 6 messages)
- Error handling and fallback responses
Security
- Environment variable configuration
- Optional Row Level Security (RLS) in Supabase
- Input validation and error handling
Project Structure
PropAgent/
βββ main.py # Main application entry point
βββ config.py # Configuration and client setup
βββ database.py # Supabase database operations
βββ whatsapp.py # WhatsApp API integration
βββ ai_chat.py # LangGraph AI conversation logic
βββ api_routes.py # FastAPI route definitions
βββ supabase_setup.sql # Database schema setup
βββ requirements.txt # Python dependencies
Development
The application uses a modular architecture:
- main.py - Clean entry point focusing on core webhook logic
- config.py - Environment variables and client initialization
- database.py - All Supabase database operations
- whatsapp.py - WhatsApp Business API integration
- ai_chat.py - LangGraph conversation flow and AI processing
- api_routes.py - REST API endpoints and webhook verification
Technologies:
- FastAPI for the web framework
- LangGraph for conversation flow management
- OpenAI GPT-4 for AI responses
- Supabase for user data storage
- WhatsApp Business API for messaging
Deployment
The application includes a Dockerfile for containerized deployment. You can deploy it to:
- Hugging Face Spaces
- Railway
- Heroku
- Any container platform
License
MIT License