import {
initializeAiChatSdk,
type OfferRedirectUrlProvider,
type MerchantCashbackProvider,
} from '@sleek/ai-chat-sdk';
// Define data providers
const offerRedirectUrlProvider: OfferRedirectUrlProvider = async (url) => {
try {
const response = await fetch(`https://api.example.com/offer?url=${encodeURIComponent(url)}`);
const data = await response.json();
return data.offerUrl || null;
} catch (error) {
return null;
}
};
const merchantCashbackProvider: MerchantCashbackProvider = async (urls) => {
try {
const response = await fetch('https://api.example.com/cashback', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ urls }),
});
const data = await response.json();
return data.cashback || {};
} catch (error) {
return {};
}
};
// Initialize SDK
const sdk = initializeAiChatSdk('your-zero-click-api-key', {
// Debugging
enableDebug: process.env.NODE_ENV === 'development',
// Chat configuration
chatConfig: {
showLogo: true,
logoUrl: 'https://your-app.com/logo.png',
colorsPrimary: ['#059669', '#10b981'],
colorsSecondary: ['#d1fae5', '#a7f3d0'],
disclaimerText: 'AI responses may contain errors',
messageLimitPerThread: 50,
// Layout
layout: {
position: {
right: '0px',
bottom: '0px',
},
size: {
width: '400px',
height: '100vh',
},
borderRadius: '0px',
boxShadow: '0 0 20px rgba(0, 0, 0, 0.1)',
},
},
// Content customization
content: {
input: {
placeholder: 'Ask about products...',
},
},
// Styling customization
styling: {
panelContainer: {
backgroundColor: 'rgba(255, 255, 255, 0.98)',
borderLeft: '3px solid #6366f1',
padding: '16px',
},
chatContentCard: {
backgroundColor: '#f9fafb',
borderRadius: '12px',
padding: '12px',
},
input: {
backgroundColor: '#ffffff',
borderColor: '#e5e7eb',
},
},
// Data providers
dataProviders: {
offerRedirectUrlProvider,
merchantCashbackProvider,
},
}, [
// Event listeners
(event) => {
console.log('SDK Event:', event.type, event.payload);
}
]);