| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Call Dashboard</title> |
| <script src="https://unpkg.com/react@17/umd/react.production.min.js"></script> |
| <script src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script> |
| <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> |
| <script src="https://unpkg.com/recharts/umd/Recharts.js"></script> |
| </head> |
|
|
| <body> |
| <div id="root"></div> |
|
|
| <script type="text/babel"> |
| const { useState, useEffect } = React; |
| const { BarChart, Bar, XAxis, YAxis, Tooltip, Legend, ResponsiveContainer } = Recharts; |
| |
| const CallDashboard = () => { |
| const [calls, setCalls] = useState([]); |
| const [stats, setStats] = useState({ incoming: 0, outgoing: 0, answered: 0, voicemail: 0, missed: 0 }); |
| const [loading, setLoading] = useState(true); |
| const [error, setError] = useState(null); |
| |
| useEffect(() => { |
| const fetchData = async () => { |
| try { |
| setLoading(true); |
| const response = await fetch('YOUR_VAPI_ENDPOINT'); |
| if (!response.ok) { |
| throw new Error('Failed to fetch data from VAPI'); |
| } |
| const data = await response.json(); |
| setCalls(data); |
| updateStats(data); |
| } catch (err) { |
| setError(err.message); |
| } finally { |
| setLoading(false); |
| } |
| }; |
| |
| fetchData(); |
| |
| // Set up polling for real-time updates (every 30 seconds) |
| const interval = setInterval(fetchData, 30000); |
| return () => clearInterval(interval); |
| }, []); |
| |
| const updateStats = (callData) => { |
| const newStats = callData.reduce((acc, call) => { |
| acc[call.direction]++; |
| acc[call.outcome]++; |
| return acc; |
| }, { incoming: 0, outgoing: 0, answered: 0, voicemail: 0, missed: 0 }); |
| setStats(newStats); |
| }; |
| |
| const chartData = [ |
| { name: 'Incoming', value: stats.incoming }, |
| { name: 'Outgoing', value: stats.outgoing }, |
| { name: 'Answered', value: stats.answered }, |
| { name: 'Voicemail', value: stats.voicemail }, |
| { name: 'Missed', value: stats.missed }, |
| ]; |
| |
| if (loading) { |
| return <div>Loading...</div>; |
| } |
| |
| if (error) { |
| return <div>Error: {error}</div>; |
| } |
| |
| return ( |
| <div style={{ fontFamily: 'Arial, sans-serif', maxWidth: '800px', margin: '0 auto', padding: '20px' }}> |
| <h1 style={{ textAlign: 'center', color: '#333' }}>Call Dashboard</h1> |
| |
| <div style={{ marginBottom: '20px' }}> |
| <h2 style={{ color: '#666' }}>Call Statistics</h2> |
| <ResponsiveContainer width="100%" height={300}> |
| <BarChart data={chartData}> |
| <XAxis dataKey="name" /> |
| <YAxis /> |
| <Tooltip /> |
| <Legend /> |
| <Bar dataKey="value" fill="#8884d8" /> |
| </BarChart> |
| </ResponsiveContainer> |
| </div> |
| |
| <div> |
| <h2 style={{ color: '#666' }}>Recent Calls</h2> |
| <table style={{ width: '100%', borderCollapse: 'collapse' }}> |
| <thead> |
| <tr style={{ backgroundColor: '#f2f2f2' }}> |
| <th style={{ padding: '10px', textAlign: 'left', border: '1px solid #ddd' }}>Phone Number</th> |
| <th style={{ padding: '10px', textAlign: 'left', border: '1px solid #ddd' }}>Direction</th> |
| <th style={{ padding: '10px', textAlign: 'left', border: '1px solid #ddd' }}>Outcome</th> |
| <th style={{ padding: '10px', textAlign: 'left', border: '1px solid #ddd' }}>Audio</th> |
| </tr> |
| </thead> |
| <tbody> |
| {calls.map((call) => ( |
| <tr key={call.id}> |
| <td style={{ padding: '10px', border: '1px solid #ddd' }}>{call.phoneNumber}</td> |
| <td style={{ padding: '10px', border: '1px solid #ddd' }}>{call.direction}</td> |
| <td style={{ padding: '10px', border: '1px solid #ddd' }}>{call.outcome}</td> |
| <td style={{ padding: '10px', border: '1px solid #ddd' }}> |
| <a href={call.audioUrl} target="_blank" rel="noopener noreferrer" style={{ color: '#0066cc', textDecoration: 'none' }}> |
| Listen |
| </a> |
| </td> |
| </tr> |
| ))} |
| </tbody> |
| </table> |
| </div> |
| </div> |
| ); |
| }; |
| |
| ReactDOM.render(<CallDashboard />, document.getElementById('root')); |
| </script> |
| </body> |
| </html> |
|
|