# WACALL Addon - Activation Guide

## ✅ Status: ACTIVATED

WhatsApp Calling addon telah berhasil diaktifkan!

---

## 🔧 Perubahan yang Dilakukan

### 1. **env.js**
```javascript
const addON = ["AI_BOT", "QR", "TELEGRAM", "WEBHOOK", "WACALL"];
```

### 2. **helper/addon/wacall/wacall.js** - Call Handler
- ✅ Handle incoming WhatsApp calls
- ✅ Process call events (initiated, ringing, connected, terminated)
- ✅ Integrate with call bot flows
- ✅ Log calls to database

### 3. **helper/addon/wacall/broadcastProcessor.js** - Broadcast Calls
- ✅ Permission request processing
- ✅ Broadcast call initiation
- ✅ Call state tracking
- ✅ Campaign management

---

## 📋 Fitur yang Aktif

| Fitur | Status |
|-------|--------|
| Incoming call handling | ✅ |
| Call bot integration | ✅ |
| Call logging | ✅ |
| Broadcast campaigns | ✅ |
| Permission requests | ✅ |
| Call flow execution | ✅ |
| Meta API integration | ✅ |

---

## 🚀 Cara Menggunakan

### Step 1: Setup Meta API Calling

Enable WhatsApp calling via Meta API:

**Endpoint:** `POST /api/wa_call/check_and_enable_call_permission`

**Response:**
```json
{
  "success": true,
  "msg": "✅ WhatsApp calling has been enabled successfully!"
}
```

---

### Step 2: Create Call Flow

**Endpoint:** `POST /api/wa_call/insert_flow`

**Body:**
```json
{
  "name": "Customer Support Bot",
  "flow_id": "flow_001",
  "source": "wa_call",
  "data": {
    "nodes": [...],
    "edges": [...]
  }
}
```

---

### Step 3: Activate Call Bot

**Endpoint:** `POST /api/wa_call/add_in_bot`

**Body:**
```json
{
  "title": "AI Support Agent",
  "flowId": "flow_001"
}
```

---

### Step 4: Create Broadcast Campaign

**Endpoint:** `POST /api/wa_call/create_broadcast`

**Body:**
```json
{
  "title": "Outbound Campaign",
  "flowId": "flow_001",
  "phonebook": { "id": 1 },
  "settings": {
    "callDelay": 5000,
    "maxConcurrentCalls": 3
  }
}
```

---

## 📡 API Endpoints

| Method | Endpoint | Function |
|--------|----------|----------|
| POST | `/api/wa_call/insert_flow` | Create/update call flow |
| GET | `/api/wa_call/get_flows` | Get user flows |
| POST | `/api/wa_call/del_flow` | Delete flow |
| POST | `/api/wa_call/add_in_bot` | Activate call bot |
| POST | `/api/wa_call/change_wa_call_bot_status` | Toggle bot status |
| GET | `/api/wa_call/get_call_bot` | Get active bots |
| GET | `/api/wa_call/call_logs` | Get call logs |
| POST | `/api/wa_call/create_broadcast` | Create campaign |
| POST | `/api/wa_call/start_permission_request` | Start permission phase |
| POST | `/api/wa_call/start_calling` | Start calling phase |
| POST | `/api/wa_call/pause_broadcast` | Pause campaign |
| POST | `/api/wa_call/check_and_enable_call_permission` | Enable Meta calling |

---

## 🔄 Call Flow

```
1. Incoming Call → Webhook received
2. handleCalls() → Process call event
3. Check active bot → If exists, load flow
4. Execute flow → AI responses / actions
5. Log call → Save to wa_call_logs
6. Call terminated → Update status
```

---

## 📦 Database Tables

Tables sudah ada di database:

| Table | Purpose |
|-------|---------|
| `wa_call_flows` | Call flow definitions |
| `wa_call_bot` | Active call bots |
| `wa_call_logs` | Call history/logs |
| `wa_call_broadcasts` | Broadcast campaigns |

Tidak perlu migrate/add tables! ✅

---

## 💡 Use Cases

### 1. AI Customer Support
- Incoming calls handled by AI bot
- Flow-based responses
- Automated call logging

### 2. Outbound Campaigns
- Bulk calling with permissions
- Track call status per contact
- Retry failed calls

### 3. Call Analytics
- View call logs
- Track campaign performance
- Monitor bot activity

---

**Last Updated:** April 9, 2026  
**WhatsApp CRM Version:** 5.9
