Add English language support to chat widget
This commit is contained in:
@@ -129,16 +129,41 @@ export default function SiteMenteVoiceWidget({
|
|||||||
// For now, simulate response
|
// For now, simulate response
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
const responses: Record<string, string> = {
|
// Spanish responses
|
||||||
|
const spanishResponses: Record<string, string> = {
|
||||||
"hola": `¡Hola! 👋 Soy el asistente de ${businessName}. ¿En qué puedo ayudarte hoy?`,
|
"hola": `¡Hola! 👋 Soy el asistente de ${businessName}. ¿En qué puedo ayudarte hoy?`,
|
||||||
"horario": `Nuestros horarios de atención son de lunes a domingo. ¿Tienes alguna pregunta específica?`,
|
"horario": `Nuestros horarios de atención son de lunes a domingo. ¿Tienes alguna pregunta específica?`,
|
||||||
"reservar": "Para hacer una reserva, puedo ayudarte ahora mismo. ¿Qué servicio te interesa?",
|
"reservar": "Para hacer una reserva, puedo ayudarte ahora mismo. ¿Qué servicio te interesa?",
|
||||||
"contacto": `Puedes llamarnos al +34 XXX XXX XXX o escribirnos aquí.`,
|
"contacto": `Puedes llamarnos al +34 XXX XXX XXX o escribirnos aquí.`,
|
||||||
"default": "Gracias por tu mensaje. Un miembro de nuestro equipo te responderá pronto. ¿Hay algo específico en lo que pueda ayudarte?"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// English responses
|
||||||
|
const englishResponses: Record<string, string> = {
|
||||||
|
"hello": `Hello! 👋 I'm the AI assistant for ${businessName}. How can I help you today?`,
|
||||||
|
"hours": `We're open Monday to Sunday. Do you have a specific question?`,
|
||||||
|
"book": "I can help you book right now. What service are you interested in?",
|
||||||
|
"contact": `You can call us at +34 XXX XXX XXX or message us here.`,
|
||||||
|
"price": "We offer packages starting from €299/month. Would you like me to tell you more?",
|
||||||
|
"cost": "We offer packages starting from €299/month. Would you like me to tell you more?",
|
||||||
|
"menu": "We serve delicious food daily. Would you like to see our menu or make a reservation?",
|
||||||
|
"reservation": "I can help you make a reservation! What date and time works for you?",
|
||||||
|
"thanks": "You're welcome! Is there anything else I can help you with?",
|
||||||
|
"thank you": "You're welcome! Is there anything else I can help you with?",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Default responses
|
||||||
|
const spanishDefault = "Gracias por tu mensaje. Un miembro de nuestro equipo te responderá pronto. ¿Hay algo específico en lo que pueda ayudarte?";
|
||||||
|
const englishDefault = "Thanks for your message! A team member will get back to you shortly. Is there anything specific I can help you with?";
|
||||||
|
|
||||||
const lowerInput = userMessage.toLowerCase();
|
const lowerInput = userMessage.toLowerCase();
|
||||||
let response = responses.default;
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
const responses = isEnglish ? englishResponses : spanishResponses;
|
||||||
|
const defaultResponse = isEnglish ? englishDefault : spanishDefault;
|
||||||
|
|
||||||
|
let response = defaultResponse;
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(responses)) {
|
for (const [key, value] of Object.entries(responses)) {
|
||||||
if (lowerInput.includes(key)) {
|
if (lowerInput.includes(key)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user