Blog

How to Wire Vapi End-of-Call Webhooks to Supabase and Twilio in Next.js

Persist voice intake, upsert leads by phone, and send application links without blocking the webhook response.

Hayaat1 min read2026-04-03
By Published Updated

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.

Vapi webhook flow diagram placeholder


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

Related reading

Voice AI Developer Hire Guide for Realtime Agents (2026)

Voice AI developer hire guide—STT, TTS, latency budgets, and Muhammad Haseeb patterns from telephony and Vapi-style integrations.

Continue reading

Vector Database Engineer Skills: What to Demand in 2026

Vector database engineer skills for production RAG—indexing, hybrid search, refresh, and MrHaseeb vetting checklist for 2026 hires.

Continue reading

Token Usage Reduction Partner: Tactics That Preserve Quality (2026)

Token usage reduction partner deliverables—compression, retrieval trimming, and eval-gated model swaps for 2026.

Continue reading

Synthetic Data Consultant: When Synthetic Beats Human Labels (2026)

Synthetic data consultant scope—generation, validation, and risk notes for 2026 fine-tune and eval programs.

Continue reading