Fix language toggle and mic access
This commit is contained in:
@@ -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 (
|
||||
<div className="fixed bottom-6 right-6 z-50">
|
||||
{/* Language Toggle */}
|
||||
<button
|
||||
onClick={() => setLanguage(lang => lang === 'en' ? 'es' : 'en')}
|
||||
className={`absolute bottom-28 right-0 ${buttonColor} px-3 py-1.5 rounded-full text-xs text-white shadow-lg mb-2 flex items-center gap-1.5 hover:scale-105 transition-transform`}
|
||||
title="Toggle Language"
|
||||
>
|
||||
{language === 'en' ? '🇪🇸 ES' : '🇬🇧 EN'}
|
||||
</button>
|
||||
|
||||
{/* Mode Toggle Button */}
|
||||
<button
|
||||
onClick={toggleMode}
|
||||
|
||||
Reference in New Issue
Block a user