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 (
{(brand.trim() || meta.defaultBrand)} · {meta.tagline}
{meta.description}
setBrand(e.target.value)} maxLength={60} />{error}
}The AI agent will call the number. You'll see the live conversation here.