Audit fixes: honest kondesk_sent tracking, remove unreachable kondesk.com endpoint
- kondesk_sent now only set to 1 when Google Sheet or email actually delivered - pushLeadToKondesk returns per-channel success flags (sheetOk, emailOk, kondeskOk) - Removed app.kondesk.com (unreachable); kept konpare.online endpoints for future - Kondesk integration note: leads flow via Konpare OSHC widget at cga.konpare.online Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3333c941c4
commit
e773335034
2 changed files with 12 additions and 6 deletions
|
|
@ -364,7 +364,8 @@ app.post('/contact', async c => {
|
|||
const lead = { fullName, email, phone, service, cricosCode, courseName: cricosName, provider: cricosProvider, message };
|
||||
const pushed = await pushLeadToKondesk(c.env, lead);
|
||||
|
||||
if (pushed.success) {
|
||||
// Mark sent when Google Sheet or email confirmed delivery (Kondesk API not available)
|
||||
if (pushed.sheetOk || pushed.emailOk) {
|
||||
await c.env.DB.prepare('UPDATE inquiries SET kondesk_sent=1 WHERE id=?')
|
||||
.bind(insert.meta.last_row_id).run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
const NOTIFY_EMAIL = 'Cgabijendra@gmail.com';
|
||||
|
||||
async function pushLeadToKondesk(env, lead) {
|
||||
// Fire all three in parallel — Google Sheet, email, Kondesk
|
||||
await Promise.allSettled([
|
||||
const [sheetsResult, emailResult, kondeskResult] = await Promise.allSettled([
|
||||
pushToGoogleSheet(env, lead),
|
||||
sendEmail(env, lead),
|
||||
pushToKondesk(env, lead),
|
||||
]);
|
||||
return { success: true };
|
||||
|
||||
const sheetOk = sheetsResult.status === 'fulfilled';
|
||||
const emailOk = emailResult.status === 'fulfilled';
|
||||
const kondeskOk = kondeskResult.status === 'fulfilled' && kondeskResult.value === true;
|
||||
|
||||
// success = true if at least Google Sheet or email went through
|
||||
return { success: sheetOk || emailOk, kondeskOk, sheetOk, emailOk };
|
||||
}
|
||||
|
||||
async function pushToGoogleSheet(env, lead) {
|
||||
|
|
@ -83,7 +88,6 @@ async function pushToKondesk(env, lead) {
|
|||
const endpoints = [
|
||||
'https://app.konpare.online/api/leads',
|
||||
'https://app.konpare.online/api/v1/leads',
|
||||
'https://app.kondesk.com/api/leads',
|
||||
];
|
||||
const payload = {
|
||||
api_key: env.KONPARE_KEY,
|
||||
|
|
@ -101,9 +105,10 @@ async function pushToKondesk(env, lead) {
|
|||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${env.KONPARE_KEY}`, 'x-api-key': env.KONPARE_KEY },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (res.ok) return;
|
||||
if (res.ok) return true;
|
||||
} catch (_) {}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export { pushLeadToKondesk };
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue