This document explains how to handle a scenario where a user is on hold while the system attempts to connect them to a specialist. If the specialist does not pick up within X seconds or if the call hits voicemail, we take an alternate action (like playing an announcement or scheduling an appointment). This solution integrates Vapi.ai for AI-driven conversations and Twilio for call bridging.
Vapi.ai does not provide a built-in way to keep the user on hold, dial a specialist, and handle cases where the specialist is unavailable. We want:
Receive Inbound Call
/inbound_call.Prompt User via Vapi
/connect).Create/Join Conference
/connect, you update the inbound call to go into a conference route.Dial Specialist
statusCallback can detect no-answer or voicemail.Detect Unanswered
Merge or Exit
Use Ephemeral Call (Optional)
<Say> the message to everyone, then ends the conference.Below is a minimal Express.js server aligned for On-Hold Specialist Transfer with Vapi and Twilio.
/inbound_call - Handling the Inbound Call/connect - Putting User on Hold and Dialing Specialist/conference - Placing Callers Into a Conference/participant-status - Handling No-Answer or Busy/announce (Optional) - Ephemeral AnnouncementEnvironment Variables
Set TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, FROM_NUMBER, TO_NUMBER, VAPI_BASE_URL, PHONE_NUMBER_ID, ASSISTANT_ID, and PRIVATE_API_KEY.
Expose Your Server
ngrok to create a public URL to port 3000./inbound_call when a call comes in.Place a Real Call
/inbound_call, and run Vapi logic./connect to conference the user and dial the specialist./participant-status.Use cURL for Testing
Vapi offers built-in functions or custom tool calls for placing a second call or transferring, you can replace the manual /connect call with that Vapi functionality. The flow remains the same: user is put in a Twilio conference, the specialist is dialed, and any no-answer events are handled.
Voicemail
If a phone’s voicemail picks up, Twilio sees it as answered. Consider advanced detection or a fallback.
Concurrent Calls
Multiple calls at once require storing separate CallSids or similar references.
Conference Behavior
startConferenceOnEnter: true merges participants immediately; endConferenceOnExit: true ends the conference when that participant leaves.
X Seconds
Decide how you detect no-answer. Typically, Twilio sets a final callStatus if the remote side never picks up.
With these steps and code, you can integrate Vapi Assistant while using Twilio’s conferencing features to hold, dial out to a specialist, and handle an unanswered or unavailable specialist scenario.