Panduan lengkap untuk mengintegrasikan widget live chat Talky ke website Anda. Widget ini mendukung real-time messaging, file upload, dan integrasi dengan AI agent WhatsApp Business.
Mulai dengan cepat dalam 3 langkah sederhana:
Download file widget-simple.js dari dashboard Talky
Tambahkan satu baris script ke website Anda
Inisialisasi dengan API key dan konfigurasi
Lihat langsung bagaimana widget bekerja sebelum mengintegrasikan ke website Anda.
Untuk website HTML biasa, tambahkan script berikut sebelum closing tag </body>:
<!DOCTYPE html>
<html>
<head>
<title>Website Anda</title>
</head>
<body>
<!-- Konten website Anda -->
<!-- Talky Live Chat Widget -->
<script src="https://talky.id/widget-min.js"></script>
<script>
// Inisialisasi widget
window.addEventListener('load', async () => {
const widget = await initLiveChat({
apiKey: "your-api-key-here",
visitorInfo: {
name: "Pengunjung",
email: "visitor@example.com"
}
});
});
</script>
</body>
</html>
Untuk aplikasi Next.js, Anda bisa menggunakan beberapa pendekatan:
import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
{/* Talky Live Chat Widget */}
<script src="https://talky.id/widget-min.js"></script>
<script
dangerouslySetInnerHTML={{
__html: `
window.addEventListener('load', async () => {
const widget = await initLiveChat({
apiKey: "your-api-key-here",
visitorInfo: {
name: "Pengunjung",
email: "visitor@example.com"
}
});
});
`
}}
/>
</body>
</Html>
)
}
import { useEffect, useState } from 'react';
export const useLiveChat = (config) => {
const [widget, setWidget] = useState(null);
const [isLoaded, setIsLoaded] = useState(false);
useEffect(() => {
// Load widget script
const script = document.createElement('script');
script.src = 'https://talky.id/widget-min.js';
script.async = true;
script.onload = async () => {
try {
const widgetInstance = await window.initLiveChat(config);
setWidget(widgetInstance);
setIsLoaded(true);
} catch (error) {
console.error('Failed to initialize live chat:', error);
}
};
document.head.appendChild(script);
return () => {
if (widget) {
widget.destroy();
}
document.head.removeChild(script);
};
}, []);
return { widget, isLoaded };
};
import { useLiveChat } from '../hooks/useLiveChat';
const LiveChatWidget = () => {
const { widget, isLoaded } = useLiveChat({
apiKey: "your-api-key-here",
visitorInfo: {
name: "Pengunjung",
email: "visitor@example.com"
}
});
return null; // Widget akan muncul otomatis
};
export default LiveChatWidget;
import React, { useEffect } from 'react';
function App() {
useEffect(() => {
// Load widget script
const script = document.createElement('script');
script.src = 'https://talky.id/widget-min.js';
script.async = true;
script.onload = async () => {
const widget = await window.initLiveChat({
apiKey: "your-api-key-here",
visitorInfo: {
name: "Pengunjung",
email: "visitor@example.com"
}
});
};
document.head.appendChild(script);
return () => {
document.head.removeChild(script);
};
}, []);
return (
<div className="App">
{/* Konten aplikasi Anda */}
</div>
);
}
Widget mendukung berbagai opsi konfigurasi untuk menyesuaikan tampilan dan perilaku:
const widget = await initLiveChat({
// Required
apiKey: "your-api-key-here",
// Optional - User Information
userId: "user_123", // Untuk session persistence per user
visitorInfo: {
name: "John Doe",
email: "john@example.com",
phone: "+62812345678",
company: "PT. Example"
}
});
https://api.talky.id
sebagai default. Untuk production, ganti dengan URL server Anda.// Konfigurasi paling sederhana - hanya API key
const widget = await initLiveChat({
apiKey: "your-api-key-here"
});
// Widget akan menggunakan default:
// - persistSession: true
// - enableFullscreen: true
const widget = await initLiveChat({
apiKey: "your-api-key-here",
// Warna kustom
primaryColor: "#10b981", // Warna utama
secondaryColor: "#059669", // Warna sekunder
backgroundColor: "#ffffff", // Background
textColor: "#1f2937", // Warna teks
agentBubbleColor: "#f3f4f6", // Bubble pesan agent
userBubbleColor: "#10b981", // Bubble pesan user
userBubbleTextColor: "#ffffff", // Teks bubble user
// Posisi widget
position: "bottom-right", // bottom-right, bottom-left
// Theme
theme: "modern" // modern, classic
});
const widget = await initLiveChat({
apiKey: "your-api-key-here",
// Session persistence
persistSession: true, // Default: true
sessionStorage: "localStorage", // "localStorage" atau "sessionStorage"
userId: "user_123", // Untuk multi-device session
// Session akan expire otomatis setelah 24 jam
});
const widget = await initLiveChat({
apiKey: "your-api-key-here",
// Fullscreen options
enableFullscreen: true, // Default: true
fullscreenBreakpoint: 768, // Auto-fullscreen di mobile (px)
});
const widget = await initLiveChat({
apiKey: "your-api-key-here",
// Event handlers
onMessage: (message) => {
console.log('New message:', message);
// Kirim ke analytics, dll
},
onTyping: (data) => {
console.log('Typing indicator:', data);
},
onError: (error) => {
console.error('Widget error:', error);
// Error handling
}
});
apiKey
- API key dari dashboarduserId
- ID user untuk sessionvisitorInfo
- Info pengunjungpersistSession
- Enable session persistenceenableFullscreen
- Enable fullscreen modeprimaryColor
- Warna utama widgetposition
- Posisi widget// Untuk website e-commerce dengan info customer
const widget = await initLiveChat({
apiKey: "your-api-key-here",
userId: customerData.id,
visitorInfo: {
name: customerData.name,
email: customerData.email,
phone: customerData.phone,
customerType: "premium",
lastOrder: customerData.lastOrderId
},
primaryColor: "#e11d48", // Brand color
onMessage: (message) => {
// Track customer interactions
analytics.track('chat_message_received', {
customerId: customerData.id,
messageType: message.sender
});
}
});
// Untuk aplikasi SaaS dengan user login
const widget = await initLiveChat({
apiKey: "your-api-key-here",
userId: user.id,
visitorInfo: {
name: user.name,
email: user.email,
plan: user.subscription.plan,
company: user.company.name,
accountValue: user.subscription.value
},
position: "bottom-left", // Tidak mengganggu dashboard
enableFullscreen: false, // Disable fullscreen di desktop
onMessage: (message) => {
// Notifikasi untuk support team
if (message.sender === 'user') {
notifySupport({
userId: user.id,
message: message.content,
priority: user.subscription.plan === 'enterprise' ? 'high' : 'normal'
});
}
}
});
// Untuk landing page dengan lead capture
const widget = await initLiveChat({
apiKey: "your-api-key-here",
visitorInfo: {
source: "landing-page",
campaign: getUrlParameter('utm_campaign'),
medium: getUrlParameter('utm_medium'),
referrer: document.referrer
},
primaryColor: "#3b82f6",
onMessage: (message) => {
// Track leads
if (message.metadata?.isRegistration) {
gtag('event', 'lead_generated', {
source: 'live_chat',
campaign: getUrlParameter('utm_campaign')
});
}
}
});
// Deteksi bahasa dan sesuaikan widget
const userLanguage = navigator.language || 'id';
const isEnglish = userLanguage.startsWith('en');
const widget = await initLiveChat({
apiKey: "your-api-key-here",
visitorInfo: {
language: userLanguage,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
},
// Sesuaikan warna berdasarkan region
primaryColor: isEnglish ? "#2563eb" : "#10b981"
});
Membuka widget chat
widget.open();
Menutup widget chat
widget.close();
Toggle buka/tutup widget
widget.toggle();
Toggle mode fullscreen
widget.toggleFullscreen();
Hapus data session (untuk logout)
widget.clearSessionData();
Hancurkan widget dan bersihkan memory
widget.destroy();
Property | Type | Description |
---|---|---|
sessionId | string | ID session saat ini |
conversationId | string | ID percakapan aktif |
isOpen | boolean | Status widget terbuka/tertutup |
isFullscreen | boolean | Status fullscreen mode |
currentView | string | View aktif: 'home', 'registration', 'chat' |
userInfo | object | Informasi user yang sedang chat |
Kemungkinan penyebab dan solusi:
// Debug: Cek apakah widget berhasil dimuat
console.log('Widget instance:', window.liveChatWidgetInstance);
console.log('initLiveChat function:', window.initLiveChat);
Widget akan fallback ke API, tapi untuk debugging:
// Cek status Socket.IO
console.log('Socket.IO loaded:', !!window.io);
if (widget.socket) {
console.log('Socket connected:', widget.socket.connected);
console.log('Socket ID:', widget.socket.id);
}
Periksa pengaturan browser dan storage:
// Cek localStorage/sessionStorage
console.log('LocalStorage available:', !!window.localStorage);
console.log('Session data:', localStorage.getItem('livechat_session_your-api-key'));
// Manual clear session
widget.clearSessionData();
Periksa ukuran dan tipe file:
Untuk debugging yang lebih detail, aktifkan debug mode:
const widget = await initLiveChat({
apiKey: "your-api-key-here",
debug: true, // Aktifkan debug logging
onError: (error) => {
console.error('Widget Error:', error);
// Kirim error ke monitoring service
errorReporting.captureException(error);
}
});