diff --git a/components/SiteMenteVoiceWidget.tsx b/components/SiteMenteVoiceWidget.tsx index 97c4633..12a4806 100644 --- a/components/SiteMenteVoiceWidget.tsx +++ b/components/SiteMenteVoiceWidget.tsx @@ -52,15 +52,15 @@ export default function SiteMenteVoiceWidget({ setErrorMsg(""); setStatus("connecting"); - // Verify mic + // Verify mic - don't block if mic check fails, let Vapi handle it try { const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); console.log("✅ Mic stream created"); + // Stop the stream after checking - we don't need it, Vapi will create its own + stream.getTracks().forEach(track => track.stop()); } catch (micErr) { - console.log("❌ Mic error:", micErr); - setErrorMsg("Microphone access denied"); - setStatus("error"); - return; + console.log("⚠️ Mic check failed, continuing anyway:", micErr); + // Don't return - let Vapi try to start the call } const vapi = new Vapi(VAPI_PUBLIC_KEY); @@ -157,11 +157,15 @@ export default function SiteMenteVoiceWidget({ const lowerInput = userMessage.toLowerCase(); - // Detect language (simple check for English keywords) - const isEnglish = /^(hello|hi|hours|book|contact|price|cost|menu|reservation|thanks|thank you|what|how|when|where)/i.test(lowerInput); + // Detect language - use manual toggle first, then auto-detect + const spanishKeywords = ['hola', 'gracias', 'si', 'no', 'por favor', 'quiero', 'necesito', 'reserva', 'horario', 'precio', 'contacto', 'dónde', 'cuándo']; + const isSpanishInput = spanishKeywords.some(keyword => lowerInput.includes(keyword)); + const isEnglishInput = /^(hello|hi|hey|thanks|yes|no|please|i want|i need|book|hours|price|contact|where|when)/i.test(lowerInput); - const responses = isEnglish ? englishResponses : spanishResponses; - const defaultResponse = isEnglish ? englishDefault : spanishDefault; + // Use language toggle, or fallback to detection + const useEnglish = language === 'en' || (!isSpanishInput && isEnglishInput); + const responses = useEnglish ? englishResponses : spanishResponses; + const defaultResponse = useEnglish ? englishDefault : spanishDefault; let response = defaultResponse; @@ -198,7 +202,7 @@ export default function SiteMenteVoiceWidget({ }; // Add state for chat panel visibility - const [showChat, setShowChat] = useState(true); + const [language, setLanguage] = useState<'en' | 'es'>('en') const buttonColor = theme === "dark" ? "bg-brand-pink" : "bg-blue-600"; const bgColor = theme === "dark" ? "bg-[#1a1625]" : "bg-white"; @@ -207,6 +211,15 @@ export default function SiteMenteVoiceWidget({ return (
+ {/* Language Toggle */} + + {/* Mode Toggle Button */}