Fix language toggle and mic access
This commit is contained in:
@@ -52,15 +52,15 @@ export default function SiteMenteVoiceWidget({
|
|||||||
setErrorMsg("");
|
setErrorMsg("");
|
||||||
setStatus("connecting");
|
setStatus("connecting");
|
||||||
|
|
||||||
// Verify mic
|
// Verify mic - don't block if mic check fails, let Vapi handle it
|
||||||
try {
|
try {
|
||||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||||
console.log("✅ Mic stream created");
|
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) {
|
} catch (micErr) {
|
||||||
console.log("❌ Mic error:", micErr);
|
console.log("⚠️ Mic check failed, continuing anyway:", micErr);
|
||||||
setErrorMsg("Microphone access denied");
|
// Don't return - let Vapi try to start the call
|
||||||
setStatus("error");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const vapi = new Vapi(VAPI_PUBLIC_KEY);
|
const vapi = new Vapi(VAPI_PUBLIC_KEY);
|
||||||
@@ -157,11 +157,15 @@ export default function SiteMenteVoiceWidget({
|
|||||||
|
|
||||||
const lowerInput = userMessage.toLowerCase();
|
const lowerInput = userMessage.toLowerCase();
|
||||||
|
|
||||||
// Detect language (simple check for English keywords)
|
// Detect language - use manual toggle first, then auto-detect
|
||||||
const isEnglish = /^(hello|hi|hours|book|contact|price|cost|menu|reservation|thanks|thank you|what|how|when|where)/i.test(lowerInput);
|
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;
|
// Use language toggle, or fallback to detection
|
||||||
const defaultResponse = isEnglish ? englishDefault : spanishDefault;
|
const useEnglish = language === 'en' || (!isSpanishInput && isEnglishInput);
|
||||||
|
const responses = useEnglish ? englishResponses : spanishResponses;
|
||||||
|
const defaultResponse = useEnglish ? englishDefault : spanishDefault;
|
||||||
|
|
||||||
let response = defaultResponse;
|
let response = defaultResponse;
|
||||||
|
|
||||||
@@ -198,7 +202,7 @@ export default function SiteMenteVoiceWidget({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Add state for chat panel visibility
|
// 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 buttonColor = theme === "dark" ? "bg-brand-pink" : "bg-blue-600";
|
||||||
const bgColor = theme === "dark" ? "bg-[#1a1625]" : "bg-white";
|
const bgColor = theme === "dark" ? "bg-[#1a1625]" : "bg-white";
|
||||||
@@ -207,6 +211,15 @@ export default function SiteMenteVoiceWidget({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed bottom-6 right-6 z-50">
|
<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 */}
|
{/* Mode Toggle Button */}
|
||||||
<button
|
<button
|
||||||
onClick={toggleMode}
|
onClick={toggleMode}
|
||||||
|
|||||||
Reference in New Issue
Block a user