# 💬 WhatsApp CRM Enterprise (PHP & MySQL)

A modern, full-featured **WhatsApp CRM & Live Chat Platform** built with **PHP (MVC)** and **MySQL**, featuring a **100% Free Self-Hosted WhatsApp Web QR Code Engine** (no Meta Developer Account needed!) as well as support for **Meta WhatsApp Cloud API (Graph API v19.0+)** and **Cloud QR Gateways (UltraMsg)**.

---

## 🌟 Key Connection Options

1. **🆓 Free Self-Hosted WhatsApp Web QR Engine (Included)**:
   - Uses the official `web.whatsapp.com` Multi-Device WebSocket protocol.
   - Scan the QR code directly inside your CRM Settings page with your phone (**WhatsApp $\rightarrow$ Linked Devices**).
   - **Cost: $0 / 100% Free Forever**, unlimited messages, no subscriptions, no Meta account required.
2. **🌐 Cloud Gateways (UltraMsg / GreenAPI)**:
   - Connect via external QR instance ID & token.
3. **☁️ Meta WhatsApp Cloud API**:
   - Official Graph API integration with phone number ID, WABA ID, and webhook validation.
4. **🧪 Offline Simulator**:
   - Test all chats, automations, and deal pipelines locally.

---

## 🚀 Quick Start (1-Click Run)

### 1. Launch Everything in 1-Click
Double-click:
```
D:\whatsapp-crm\start-crm-and-whatsapp.bat
```
*(This automatically launches the free WhatsApp Web QR Engine on port 3000 and the PHP CRM on port 8000!)*

### 2. Scan QR Code
1. Open your browser: `http://localhost:8000/login`
2. Log in with:
   - **Email:** `admin@crm.local`
   - **Password:** `password123`
3. Go to **Settings $\rightarrow$ WhatsApp Connection** (`/settings`).
4. Select **🆓 Free WhatsApp Web QR** $\rightarrow$ A live QR code will appear on screen.
5. On your phone, open **WhatsApp $\rightarrow$ Linked Devices $\rightarrow$ Link a Device** and scan the QR code.
6. The status will immediately turn **🟢 WhatsApp Connected** with your linked phone number!

---

## ⚡ Live Features

- **Live 3-Column WhatsApp Web Inbox**:
  - Send & receive live text, images, PDFs, audio.
  - Canned quick replies (type `/` to trigger instant templates).
  - Inline CRM lead profile, tags, and notes.
- **Sales Pipeline Kanban Board**:
  - Drag-and-drop deals across sales stages.
  - Forecast revenue and win rate.
- **Automation & Bot Engine**:
  - Keyword trigger auto-replies (e.g. typing "pricing" or "demo").
  - Welcome bot for new leads.
  - Working hours with automated out-of-office response.
- **Contact Management & CSV Bulk Import/Export**:
  - Full lead segmentation by tags and lifecycle stage.

---

## 📁 Project Structure

```
D:\whatsapp-crm/
├── app/                            # PHP MVC Core, Controllers, Models, Services
├── database/                       # schema.sql, seeds.sql, installer.php
├── public/                         # Web root (index.php, webhook.php, assets)
├── views/                          # Blade/PHP UI templates (chat, pipeline, etc.)
├── whatsapp-server/                # Free Self-Hosted WhatsApp Web QR Engine (Node.js/Baileys)
│   ├── package.json
│   └── server.js                   # WhatsApp Multi-Device WebSocket bridge
├── start-whatsapp-qr.bat           # 1-Click Launcher for WhatsApp Web Engine
├── start-crm-and-whatsapp.bat      # All-in-one Launcher for CRM + WhatsApp Web
├── .env & .htaccess                # Configuration & Clean URLs
└── README.md
```
