Modul WhatsApp & Device mencakup pairing device, live chat, AI agent, broadcast, dan integrasi ke engine WhatsApp (Node.js) + engine bot (Node.js) + backend Go.
File kunci
| File | Baris | Peran |
|---|---|---|
app/Http/Controllers/DeviceController.php | 923 | Device lifecycle: pairing, status, logout |
app/Http/Controllers/LiveChatController.php | 1.213 | Live chat, agent assignment, CS rotasi |
app/Http/Controllers/AgentAiController.php | 1.477 | AI agent CRUD, prompt, QnA, follow-up |
app/Http/Controllers/BroadcastscedularController.php | 1.265 | Scheduled broadcast |
app/Http/Controllers/BroadcastchatController.php | 768 | Manual broadcast |
app/Services/DeviceService.php | 37 | Helper device info (hampir tidak dipakai) |
resources/js/Pages/LiveChat/Index.vue | 5.681 | UI live chat (god component) |
Device vs Agent — perbedaan
| Device | Agent | |
|---|---|---|
| Model | app/Models/Device.php | app/Models/Agent.php |
| Peran | Sesi WhatsApp (instance di engine WA) | Konfigurasi AI agent |
| Field utama | no_wa, port, token, is_connected, agent_id | prompt, qna_conditional, followup, welcome_messages |
| Relasi | belongsTo(Agent) via agent_id | hasMany(Device) |
| Dibuat saat | Pairing QR di engine WA | Admin konfigurasi AI di UI |
Satu agent bisa dipetakan ke banyak device. Device tanpa agent_id = pesan masuk tidak diproses AI.
DeviceController — method utama
| Method | Fungsi |
|---|---|
index() | Halaman Device/Index — list device + agent + kuota |
getQr() | Pairing QR — GET url_engine . 'api/qrcode?instance=' |
store() | Buat device baru — generate port, token, panggil engine api/new |
list() | List paginate, tiap row cek status realtime via deviceInfo() |
deviceInfo($id) | Cek status — GET url_engine . 'api/device-info?instance=' |
restartSession() | Restart sesi — POST url_engine . 'api/new' |
reload($id) | Reload — GET url_engine . 'reload' |
logout($id) | Logout device — GET url_engine . 'api/logout?instance=' |
destroy($id) | Hapus device + panggil engine logout + soft-delete |
update() | Update agent_id + sync handle_by_bot di ChatList |
generatePortDevice() | Alokasi port 3-digit acak (100–999) |
LiveChatController
Chat models — perbedaan
| Model | Peran |
|---|---|
ChatList | Daftar percakapan aktif (inbox view) |
ChatHistory | Riwayat pesan per percakapan |
ChatOrder | Order yang dibuat dari percakapan |
ChatCheckout | Checkout yang dibuat dari percakapan |
Real-time
Socket.IO (composables/useSocket.js) — connect di app.js setup() ke url_engine. Frontend mendengar event socket untuk update chat list real-time.
AI Agent
AgentAiController mengelola konfigurasi AI agent:
| Aspek | Field di model Agent |
|---|---|
| Prompt | prompt (default dari config('default_data.prompt')) |
| QnA | qna_conditional — array {question, answer} |
| Follow-up | followup — map keyed by type → {is_generate_ai, message, sending_time, image} |
| Welcome message | welcome_messages — array {type, message, fileName?} |
| Limit | history_limit (default 10), message_limit (default 1000), message_await (default 15) |
Testing inbox
AgentTestingInboxController — UI untuk test AI agent dengan input bebas. Dipanggil via url_ai_agent (Engine Bot).
Engine WhatsApp integration
| Method | Endpoint | Fungsi |
|---|---|---|
getQr() | GET api/qrcode?instance= | Ambil QR untuk pairing |
store() | POST api/new | Buat instance baru |
deviceInfo() | GET api/device-info?instance= | Cek status koneksi |
logout() | GET api/logout?instance= | Logout device |
restartSession() | POST api/new | Restart sesi |
reload() | GET reload | Reload sesi |
createNotif() | POST push-notif | Push notif ke device |
updateDataSource() | POST update-chatlist | Sync chat list |
Host produksi tidak konsisten
engine.dazo.id — di OrderController, Downgrade, SubscriptionNotif
engine-wa.dazo.id — di AgentAiController, DeviceServiceKonfirmasi mana yang benar sebelum menulis URL baru.
Engine Bot (AI) integration
| Method | Endpoint | Fungsi |
|---|---|---|
AgentTestingInboxController | url_ai_agent | Test AI agent |
DokuCheckoutController::notifyEngineBot() | {engine_bot_url}/api/webhook/payment-notification | Notify pembayaran ke Engine Bot |
Token: config('services.engine_bot.token') (ENGINE_BOT_TOKEN di .env).
Backend Go integration
| Method | Endpoint | Fungsi |
|---|---|---|
OrderController::createOrder | POST {url_api}send_message | Kirim pesan WA ke pembeli |
OrderController::createOrder | POST {url_api}send_image | Kirim gambar |
DigitalProductService::sendMessage | POST {url_api}send_message | Kirim link produk digital |
LiveChatController (via url_api) | — | Escalate chat |
Broadcast
| Controller | Peran |
|---|---|
BroadcastscedularController | Broadcast terjadwal (scheduler) |
BroadcastchatController | Broadcast manual |
DeviceService di-inject di BroadcastscedularController untuk cek status device sebelum kirim.
Template & Response
| Model | Peran |
|---|---|
TemplateMessage | Template pesan WhatsApp (approved Meta) |
ResponseTemplate | Quick reply untuk CS |
Chatbot | Konfigurasi chatbot rule-based |
Flow | Alur percakapan (conversation flow) |
WellcomeMessage | Pesan welcome otomatis |
Socket.IO
composables/useSocket.js (46 baris):
const socket = io(global.url_engine || 'http://localhost:5002', {
transports: ['websocket'],
autoConnect: true
});initSocket() dipanggil di app.js setup() — connect di setiap page load. Dipakai di 11 file.
Langkah berikutnya
- Butuh kirim pesan WA dari order? Baca Order.
- Butuh notif pembayaran ke WA? Baca Wallet.
- Detail URL service? Baca External Services.