ishaan p.
02/21/2025, 2:10 PMPraveen
02/22/2025, 12:12 PMishaan p.
02/23/2025, 9:05 AMishaan p.
02/23/2025, 8:09 PMishaan p.
02/23/2025, 8:09 PMShubham Bajaj
02/24/2025, 11:16 AMts
const CallDownloader = ({ callId }) => {
const downloadRecording = async () => {
// Fetch call data to get artifact URLs
const call = await vapiClient.calls.get(callId);
if (call.artifact?.recordingUrl) {
// Trigger browser download
window.open(call.artifact.recordingUrl);
}
};
const downloadTranscript = async () => {
const call = await vapiClient.calls.get(callId);
if (call.artifact?.transcript) {
// Create and trigger download of transcript file
const blob = new Blob([call.artifact.transcript], { type: 'text/plain' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `transcript-${callId}.txt`;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}
};
return (
<div>
<button onClick={downloadRecording}>Download Recording</button>
<button onClick={downloadTranscript}>Download Transcript</button>
</div>
);
};
b) Integration with VAPI Events
ts
useEffect(() => {
const handleMessage = (message) => {
if (message.type === 'transcript' && message.transcriptType === 'final') {
const { type, ...payload } = message;
setMessages((prevMessages) => [
...prevMessages,
{ role: payload.role, content: payload.transcript },
]);
}
};
const handleCallEnd = () => {
setMessages([]);
};
vapi.on('message', handleMessage);
vapi.on('call-end', handleCallEnd);
// Cleanup function to remove the listeners
return () => {
vapi.off('message', handleMessage);
vapi.off('call-end', handleCallEnd);
};
}, [vapi]);
With this you can also listen for call end events to automatically trigger downloads.ishaan p.
02/24/2025, 1:42 PMPraveen
02/26/2025, 1:50 AM