The key issue is that once a call ends, no further requests are sent to your LLM provider, as mentioned by Mason. This means your assistant can't execute any tools after the call has ended.
Here's how to solve this:
Option 1: Create a Webhook Server to Handle Call End Events
1. Set up a server to receive webhook notifications when calls end
2. In your webhook server, detect specific endedReason values (like "customer-ended-call" or "silence-timed-out")
3. When these events occur, check if data was collected but not sent, and trigger your function manually
Here's how to implement this:
1. Create a webhook endpoint in your server code
2. Configure your Vapi assistant to use this webhook URL in the server.url field
3. In your webhook handler, process the status-update event type that includes the endedReason
4. If the endedReason is one you care about (customer-ended-call or silence-timed-out), and you have partial data, trigger your function
Sample webhook handler code:
// Sample webhook handler
app.post('/webhook', (req, res) => {
const data = req.body;
const message = data.message || {};
if (message.type === 'status-update' && message.status === 'ended') {
const endedReason = message.endedReason;
// Check if this is a case we need to handle
if (endedReason === 'customer-ended-call' || endedReason === 'silence-timed-out') {
// Get the call ID and any data you've stored
const callId = data.call?.id;
// If you have partial data for this call stored somewhere
// Call your function to send the email with whatever data was collected
if (callId && hasPartialData(callId)) {
const collectedData = getPartialData(callId);
sendEmailWithData(collectedData);
}
}
}
res.json({ success: true });
});
Option 2: Store Partial Data During the Call
Another approach is to continuously store the collected data during the call:
1. Modify your assistant logic to incrementally save collected information to your backend as soon as it's gathered
2. Set up a webhook to receive call end events
3. When you get a call end event, if data was collected but the function wasn't called, trigger it manually
This would involve:
1. Creating endpoints to store partial data during the conversation
2. Having your assistant make API calls to store data as it's collected
3. Using your webhook to check if the function was already called when the call ends
Implementation Steps
1. Set up a webhook server that can receive call status updates
2. Configure your Vapi assistant to send webhooks to your server
3. In your webhook handler, when you receive a call end event with endedReason "customer-ended-call" or "silence-timed-out", check if you have partial data for that call
4. If data exists but the functionsEnquiry wasn't called, manually trigger it
This approach ensures that even if the call ends unexpectedly, you'll still process and send the data that was collected up to that point.
Would you like me to elaborate on any of these solutions further?