ARENAG.ONE
02/21/2025, 8:21 AMyandos666
02/21/2025, 11:03 AMVapi
02/22/2025, 11:44 AMserverMessages: ['end-of-call-report']
2\. Here's how to implement the server endpoint to handle the end-of-call report:
import express from 'express';
import type { EndOfCallReportMessage } from '@vapi-ai/web';
const app = express();
app.use(express.json());
app.post('/vapi-webhook', async (req, res) => {
const message = req.body as EndOfCallReportMessage;
if (message.type === 'end-of-call-report') {
// Store call data in your database
await storeCallData({
callId: message.call?.id,
transcript: message.artifact?.transcript,
startedAt: message.startedAt,
endedAt: message.endedAt,
durationSeconds: message.durationSeconds,
// Additional data available in the report
recordingUrl: message.artifact?.recordingUrl,
stereoRecordingUrl: message.artifact?.stereoRecordingUrl
});
}
res.status(200).json({ success: true });
});
3\. Configure your assistant to send server messages to your webhook:
This solution is better than using client-side events because:
1\. The end-of-call report is sent after all processing is complete, ensuring you get the final transcript
2\. It's more reliable since it's server-to-server communication
3\. It includes additional metadata like duration, timestamps, and recording URLs
4\. It works even if the client disconnects before the call ends
Let me know if you need any clarification on implementing the webhook handler or configuring the assistant!