const KAPSO_API_KEY = 'YOUR_API_KEY';
const PLATFORM_API_URL = 'https://api.kapso.ai/platform/v1';
const WHATSAPP_API_URL = 'https://api.kapso.ai/meta/whatsapp';
async function onboardCustomer(customerData) {
// 1. Create customer
const customer = await fetch(`${PLATFORM_API_URL}/customers`, {
method: 'POST',
headers: {
'X-API-Key': KAPSO_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({ customer: customerData })
}).then(r => r.json());
// 2. Generate setup link
const setupLink = await fetch(
`${PLATFORM_API_URL}/customers/${customer.data.id}/setup_links`,
{
method: 'POST',
headers: { 'X-API-Key': KAPSO_API_KEY }
}
).then(r => r.json());
return setupLink.data.url;
}
async function sendMessage(phoneNumberId, recipientPhone, message) {
return fetch(`${WHATSAPP_API_URL}/v21.0/${phoneNumberId}/messages`, {
method: 'POST',
headers: {
'X-API-Key': KAPSO_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
messaging_product: 'whatsapp',
to: recipientPhone,
type: 'text',
text: { body: message }
})
});
}