Bot WA dengan Artificial Intelligence (AI)
Cara buat bot WhatsApp dengan AI. Lebih pintar, lebih natural, bisa jawab pertanyaan kompleks. Upgrade bot biasa ke AI!
Bot keyword sudah tidak cukup!
Customer ingin jawaban yang natural dan cerdas, bukan response kaku. Bot AI adalah solusinya.
Bot Biasa vs Bot AI
❌ BOT KEYWORD (BIASA):
Customer: "Harga kaos yang warna gelap ukuran sedang?"
Bot: "Maaf, saya tidak mengerti. Ketik HARGA untuk info harga."
(Tidak match keyword "harga" karena kalimatnya beda)
✅ BOT AI:
Customer: "Harga kaos yang warna gelap ukuran sedang?"
Bot: "Kaos warna hitam/navy size M harganya Rp 150.000 ya kak!
Ready stock. Mau order yang mana?"
(Paham maksud meski kata-katanya berbeda)Keunggulan Bot AI
1. Paham Bahasa Natural
Bot AI bisa memahami:
- "Brp hrgnya?" → Berapa harganya?
- "ada yg wrna item?" → Ada warna hitam?
- "bs cod gk?" → Bisa COD tidak?
- "pgn order" → Mau order
Tidak perlu keyword exact match!2. Jawab Pertanyaan Kompleks
Customer: "Aku mau beli kaos buat hadiah ulang tahun
pacar cowok, budget 200rb, dia orangnya
suka warna gelap dan badannya tinggi kurus"
Bot AI: "Untuk pacar kakak yang tinggi kurus,
recommend size M atau L tergantung prefer
loose/fit. Ini rekomendasinya:
1. Kaos Premium Hitam - Rp 175k
2. Kaos Oversized Navy - Rp 185k
Dua-duanya cocok untuk kado! Mau yang mana?"3. Konteks Percakapan
Turn 1:
Customer: "Ada kaos hitam?"
Bot: "Ada kak! Size S-XL ready."
Turn 2:
Customer: "Yang L berapa?"
Bot: "Kaos hitam size L Rp 150.000 ya kak!"
(Ingat context dari turn sebelumnya)
Turn 3:
Customer: "Oke order 2"
Bot: "Siap! 2x Kaos hitam size L = Rp 300.000
Mau kirim ke mana kak?"
(Masih ingat semua context)Cara Kerja Bot AI
┌─────────────────────────────────────────┐
│ Customer Message │
│ "brp ongkir ke sby pake jne?" │
└────────────────┬────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ AI MODEL │
│ (ChatGPT/Claude/Gemini/dll) │
│ │
│ + System Prompt (knowledge toko) │
│ + Conversation History │
└────────────────┬────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ AI Response │
│ "Ongkir ke Surabaya via JNE: │
│ - REG: Rp 15.000 (2-3 hari) │
│ - YES: Rp 25.000 (1 hari)" │
└─────────────────────────────────────────┘Implementasi Bot AI
Dengan ChatGPT (OpenAI):
javascript
const OpenAI = require('openai');
const { Client, LocalAuth } = require('whatsapp-web.js');
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const client = new Client({ authStrategy: new LocalAuth() });
// Conversation history per user
const conversations = new Map();
// System prompt (knowledge toko)
const systemPrompt = `Kamu adalah CS untuk Toko Fashion "StyleKu".
INFORMASI TOKO:
- Produk: Kaos, Kemeja, Celana
- Harga kaos: Rp 150.000
- Harga kemeja: Rp 250.000
- Size: S, M, L, XL
- Pengiriman: JNE, J&T, SiCepat
- Pembayaran: Transfer BCA/Mandiri, COD Jakarta
CARA KAMU MENJAWAB:
- Ramah, pakai emoji secukupnya
- Panggil "kak"
- Jawab singkat tapi lengkap
- Tawarkan bantuan lanjutan`;
client.on('message', async msg => {
const userId = msg.from;
// Get or create conversation history
if (!conversations.has(userId)) {
conversations.set(userId, []);
}
const history = conversations.get(userId);
// Add user message to history
history.push({ role: 'user', content: msg.body });
// Keep last 10 messages only
if (history.length > 10) {
history.splice(0, history.length - 10);
}
// Call OpenAI
const response = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [
{ role: 'system', content: systemPrompt },
...history
],
max_tokens: 500,
temperature: 0.7
});
const aiReply = response.choices[0].message.content;
// Add AI response to history
history.push({ role: 'assistant', content: aiReply });
// Send reply
await msg.reply(aiReply);
});
client.initialize();Dengan Google Gemini (Free Tier):
javascript
const { GoogleGenerativeAI } = require('@google/generative-ai');
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });
async function getAIResponse(message, history) {
const chat = model.startChat({
history: history,
generationConfig: {
maxOutputTokens: 500,
},
});
const result = await chat.sendMessage(message);
return result.response.text();
}Hybrid Approach (Recommended)
javascript
// Gabungan keyword + AI untuk efisiensi
async function handleMessage(msg) {
const text = msg.body.toLowerCase();
// 1. Check exact keywords dulu (FREE, cepat)
if (text === 'menu' || text === 'help') {
return getMenuMessage();
}
if (text === 'katalog') {
return getCatalogMessage();
}
// 2. Check simple patterns
if (text.includes('harga') && text.includes('kaos')) {
return 'Harga kaos mulai Rp 150.000 ya kak! Size S-XL ready.';
}
// 3. Fall back ke AI untuk yang kompleks
return await getAIResponse(msg.body);
}Kenapa Hybrid?
- Keyword: Gratis, cepat, predictable
- AI: Flexible, natural, tapi ada cost
- Hybrid: Best of both worlds, hemat biaya
Tips Optimasi Bot AI
1. System Prompt yang Bagus
GOOD System Prompt:
✅ Jelas role-nya (CS toko X)
✅ Knowledge lengkap (produk, harga, policy)
✅ Tone & style defined (casual/formal)
✅ Batasan jelas (apa yang boleh/tidak)
✅ Format response (singkat, pakai emoji, dll)2. Context Management
javascript
// Simpan hanya yang penting
function summarizeHistory(history) {
if (history.length <= 6) return history;
// Simpan 2 awal (context) + 4 terakhir
return [
...history.slice(0, 2),
{ role: 'system', content: '[...conversation continues...]' },
...history.slice(-4)
];
}3. Fallback Handling
javascript
// Jika AI tidak yakin, arahkan ke human
const aiResponse = await getAIResponse(message);
if (aiResponse.includes('tidak yakin') ||
aiResponse.includes('hubungi admin')) {
// Forward ke admin
await notifyAdmin(msg.from, message);
return 'Untuk pertanyaan ini, admin akan membantu ya kak. Mohon tunggu sebentar! 🙏';
}
return aiResponse;Perbandingan AI Providers
| Provider | Model | Harga | Kelebihan |
|---|---|---|---|
| OpenAI | GPT-4o-mini | ~Rp 1-5/chat | Akurat, cepat |
| Gemini Flash | Free tier! | Gratis untuk mulai | |
| Anthropic | Claude Haiku | ~Rp 2-5/chat | Natural, aman |
| Local | Llama/Mistral | Rp 0 (self-host) | Privacy, tapi butuh server |
Biaya Realistis
📊 ESTIMASI BIAYA (GPT-4o-mini):
Per conversation (5 turn): ~Rp 5-10
500 chat/bulan: ~Rp 2,500 - 5,000
2000 chat/bulan: ~Rp 10,000 - 20,000
Sangat affordable! ☕ Lebih murah dari kopiFAQ
Apakah AI selalu akurat?
Tidak 100%, tapi dengan system prompt yang baik, akurasi bisa 90%+. Selalu sediakan fallback ke human.
Butuh skill coding?
Untuk setup sendiri, ya. Tapi banyak platform no-code yang sudah support AI integration.
Aman untuk bisnis?
Ya, asalkan: jangan simpan data sensitif di prompt, gunakan provider terpercaya, dan selalu ada human oversight.
Kesimpulan
Bot AI = Customer experience next level!
| Bot Keyword | Bot AI |
|---|---|
| Kaku, exact match | Natural, flexible |
| Tidak paham variasi | Paham berbagai cara tanya |
| Tidak ada context | Ingat percakapan |
| Limited responses | Unlimited possibilities |
Upgrade ke AI, tingkatkan kepuasan customer!