Skip to main content

Code Examples

const KEY  = 'sl_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const BASE = 'https://slazbvfvliieskvkjtav.supabase.co/functions/v1/api-gateway';

async function suggest(replyText, leadName, context) {
const res = await fetch(`${BASE}/v1/suggest`, {
method: 'POST',
headers: { 'X-SalesLobe-Key': KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({ reply_received: replyText, lead_name: leadName, campaign_context: context })
});
if (!res.ok) { const e = await res.json(); throw new Error(e.error.message); }
return res.json();
}

async function sendReply(replyId, body, original) {
const res = await fetch(`${BASE}/v1/replies/${replyId}/send`, {
method: 'POST',
headers: { 'X-SalesLobe-Key': KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({ body, original_suggestion: original, edited: true })
});
return res.json();
}

async function updateLead(replyId, classification) {
const res = await fetch(`${BASE}/v1/leads/${replyId}`, {
method: 'PATCH',
headers: { 'X-SalesLobe-Key': KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({ classification })
});
return res.json();
}