Spaces:
Sleeping
Sleeping
File size: 8,865 Bytes
d867e05 252a04f d867e05 252a04f d867e05 252a04f d867e05 252a04f d867e05 252a04f d867e05 252a04f d867e05 252a04f d867e05 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { WEBHOOK_URL } from '../lib/webrtc'
import VoiceSettings from './VoiceSettings'
import { buildVoiceCustoms } from '../lib/voiceOptions'
const CALL_META = {
university: {
label: 'University Call Agent',
tagline: 'Admissions',
accent: '#60d0f0',
icon: '⬡',
description: 'AI admissions counsellor Sneha will call the number and guide the prospective student through the admissions process.',
agentName: 'Sneha',
defaultBrand: 'NIMS University',
},
realestate: {
label: 'Real Estate Call Agent',
tagline: 'Sales',
accent: '#f0b060',
icon: '⬢',
description: 'AI sales executive Riya will call the number and qualify the property buyer through a natural conversation.',
agentName: 'Riya',
defaultBrand: 'Skyline Greens',
},
coaching: {
label: 'Coaching Institute Agent',
tagline: 'Admissions',
accent: '#b088f0',
icon: '◆',
description: 'AI counsellor Aarohi will call the lead and book a scholarship test, counselling, or campus visit through a natural conversation.',
agentName: 'Aarohi',
defaultBrand: 'Bansal Classes',
},
medical: {
label: 'Medical OPD Agent',
tagline: 'Front Desk',
accent: '#5fd0a0',
icon: '✚',
description: 'AI front-desk assistant Meera answers the OPD line, books appointments, and routes queries — with a built-in safety interrupt for emergencies.',
agentName: 'Meera',
defaultBrand: 'Sanjeevani Hospital',
},
hotel: {
label: 'Hotel Concierge Agent',
tagline: 'Pre-arrival',
accent: '#f0a0c0',
icon: '❖',
description: 'AI concierge Kabir calls a confirmed guest before check-in to confirm arrival, capture preferences, and offer relevant add-ons.',
agentName: 'Kabir',
defaultBrand: 'The Grand Rambagh',
},
}
// Server URL — same host as WEBHOOK_URL, just port 7777
const SERVER_URL = WEBHOOK_URL
export default function CallSetup({ type }) {
const navigate = useNavigate()
const meta = CALL_META[type]
const [digits, setDigits] = useState('')
const [brand, setBrand] = useState('')
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [voiceSettings, setVoiceSettings] = useState({
sttProvider: 'soniox',
sttLanguages: ['hi', 'en'],
})
if (!meta) {
navigate('/', { replace: true })
return null
}
function handleDigits(e) {
const val = e.target.value.replace(/\D/g, '').slice(0, 10)
setDigits(val)
setError('')
}
async function handleCall() {
if (digits.length < 10) return setError('Enter a valid 10-digit number')
setError('')
setLoading(true)
const sessionId = crypto.randomUUID()
const phone = `+91${digits}`
try {
const res = await fetch(`${SERVER_URL}/call`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
type,
phone,
brand: brand.trim() || undefined,
session_id: sessionId,
voiceSettings: Object.keys(voiceSettings).length ? buildVoiceCustoms(voiceSettings) : null,
}),
})
if (!res.ok) {
const err = await res.json().catch(() => ({ error: 'Request failed' }))
setError(err.error || 'Failed to place call')
setLoading(false)
return
}
navigate(`/call/${type}/${sessionId}`, {
state: { phone, agentName: meta.agentName, label: meta.label },
})
} catch (e) {
setError(e.message || 'Network error')
setLoading(false)
}
}
return (
<div style={s.page}>
<div style={{ ...s.glow, background: `radial-gradient(ellipse 60% 50% at 30% 60%, ${meta.accent}08 0%, transparent 70%)` }} />
<div style={s.inner}>
<button style={s.back} onClick={() => navigate('/')}>← back</button>
<div style={{ ...s.iconBox, background: `${meta.accent}15`, color: meta.accent }}>
{meta.icon}
</div>
<h1 style={s.title}>{meta.label}</h1>
<p style={{ ...s.tagline, color: meta.accent }}>{(brand.trim() || meta.defaultBrand)} · {meta.tagline}</p>
<p style={s.desc}>{meta.description}</p>
<label style={s.fieldLabel}>Business name</label>
<input
style={s.brandInput}
type="text"
placeholder={meta.defaultBrand}
value={brand}
onChange={e => setBrand(e.target.value)}
maxLength={60}
/>
<label style={s.fieldLabel}>Phone number</label>
<div style={s.inputGroup}>
<div style={s.prefix}>+91</div>
<input
style={s.input}
type="tel"
inputMode="numeric"
placeholder="98XXXXXXXX"
value={digits}
onChange={handleDigits}
onKeyDown={e => e.key === 'Enter' && !loading && handleCall()}
maxLength={10}
autoFocus
/>
</div>
<VoiceSettings value={voiceSettings} onChange={setVoiceSettings} />
{error && <p style={s.error}>{error}</p>}
<button
style={{ ...s.callBtn, background: meta.accent, opacity: loading ? .6 : 1, cursor: loading ? 'not-allowed' : 'pointer' }}
onClick={handleCall}
disabled={loading}
>
{loading ? 'Placing call…' : `Call with ${meta.agentName} →`}
</button>
<p style={s.fine}>
The AI agent will call the number. You'll see the live conversation here.
</p>
</div>
</div>
)
}
const s = {
page: {
minHeight: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: '48px 20px',
position: 'relative',
overflowY: 'auto',
},
glow: {
position: 'fixed', inset: 0,
pointerEvents: 'none',
},
inner: {
width: '100%',
maxWidth: 440,
display: 'flex',
flexDirection: 'column',
position: 'relative',
zIndex: 1,
},
back: {
alignSelf: 'flex-start',
fontFamily: 'var(--mono)',
fontSize: 11,
color: 'var(--muted)',
background: 'none',
border: 'none',
cursor: 'pointer',
letterSpacing: '.08em',
padding: 0,
marginBottom: 32,
},
iconBox: {
width: 56,
height: 56,
borderRadius: 14,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 24,
marginBottom: 20,
},
title: {
fontSize: 'clamp(28px, 5vw, 42px)',
fontWeight: 800,
letterSpacing: '-.03em',
lineHeight: 1.05,
marginBottom: 6,
},
tagline: {
fontFamily: 'var(--mono)',
fontSize: 9,
letterSpacing: '.22em',
textTransform: 'uppercase',
marginBottom: 14,
},
desc: {
fontFamily: 'var(--mono)',
fontSize: 11,
color: 'var(--muted)',
lineHeight: 1.7,
marginBottom: 36,
},
fieldLabel: {
fontFamily: 'var(--mono)',
fontSize: 9,
letterSpacing: '.18em',
textTransform: 'uppercase',
color: 'var(--muted)',
marginBottom: 8,
},
brandInput: {
background: 'var(--surface)',
border: '1px solid var(--border2)',
borderRadius: 8,
color: 'var(--text)',
fontFamily: 'var(--mono)',
fontSize: 15,
padding: '14px 16px',
outline: 'none',
marginBottom: 20,
},
inputGroup: {
display: 'flex',
alignItems: 'center',
border: '1px solid var(--border2)',
borderRadius: 8,
overflow: 'hidden',
marginBottom: 12,
},
prefix: {
fontFamily: 'var(--mono)',
fontSize: 14,
color: 'var(--muted)',
padding: '14px 14px',
background: 'var(--surface)',
borderRight: '1px solid var(--border2)',
flexShrink: 0,
letterSpacing: '.06em',
},
input: {
flex: 1,
background: 'var(--surface)',
border: 'none',
color: 'var(--text)',
fontFamily: 'var(--mono)',
fontSize: 18,
padding: '14px 16px',
outline: 'none',
letterSpacing: '.1em',
},
error: {
fontFamily: 'var(--mono)',
fontSize: 11,
color: 'var(--danger)',
marginBottom: 12,
letterSpacing: '.06em',
},
callBtn: {
color: '#0a0a0a',
border: 'none',
fontFamily: 'var(--sans)',
fontSize: 14,
fontWeight: 700,
letterSpacing: '.06em',
padding: '16px 24px',
borderRadius: 8,
cursor: 'pointer',
marginTop: 8,
marginBottom: 16,
transition: 'opacity .15s',
},
fine: {
fontFamily: 'var(--mono)',
fontSize: 10,
color: 'var(--muted)',
letterSpacing: '.1em',
textAlign: 'center',
lineHeight: 1.6,
},
}
|