Direct answer (40 words)
Handle only Vapi’s end-of-call-report, recursively extract caller fields from nested JSON, upsert clients or caregivers on phone conflict, insert intake_logs, then fire Twilio SMS with .catch() so the webhook returns 200 fast and Twilio/Vapi do not retry unnecessarily.
Voice intake fails operationally when webhooks are slow or brittle. This codebase treats terminal call reports as the source of truth, uses defensive extraction for variable payload shapes, and decouples SMS from the HTTP response.
Ignore non-terminal events early
if (body.message.type !== "end-of-call-report") {
return NextResponse.json({ message: "Ignored event" }, { status: 200 });
}
Recursive helpers for nested Vapi payloads
function findKey(obj: any, key: string): any {
if (!obj || typeof obj !== "object") return null;
if (key in obj) return obj[key];
for (const k in obj) {
const found = findKey(obj[k], key);
if (found) return found;
}
return null;
}
function findCallSummary(obj: any): string | null {
if (!obj || typeof obj !== "object") return null;
if (obj.name === "Call Summary") {
return typeof obj.result === "string" ? obj.result : null;
}
for (const k in obj) {
const found = findCallSummary(obj[k]);
if (found) return found;
}
return null;
}
Upsert + non-blocking SMS
if (phone) {
sendApplicationLink(phone, "caregiver", caregiver.id).catch((smsError) => {
console.error("❌ Failed to send SMS to caregiver:", smsError);
// Continue execution even if SMS fails
});
}
Why it matters: Vapi and Twilio both penalize slow or failing endpoints. Returning quickly while logging and SMS run asynchronously keeps the voice → CRM → SMS pipeline reliable under load.

Next step: Read the full architecture and security notes in Hayaat Intake AI — case study.